How do I prevent click through

Get help using Construct 2

Post » Tue Aug 09, 2016 3:42 pm

I know this has been covered a little in a few other threads but none cover my requirements.
Is there a way to prevent click/tap through? I have multiple sprites that can be clicked/tapped on to be selected, I have random powerups spawning to be collected that can appear on top of them, when you click/tap on the powerups it selects the sprite below, which I don't want. Worse is with one where it selects the sprite and activates the powerup all in one go.
I need to be able to ignore all underlying sprites with a power up on top, but still have them selectable if you were to click/tap on them (if that makes sense?).

Any thoughts or ideas?
B
6
S
1
Posts: 19
Reputation: 440

Post » Tue Aug 09, 2016 8:03 pm

Do you mean still have them selectable if you were to click/tap on them if a power up is not on top of them? I guess so, because otherwise that doesn't make a lot of sense. You can check to see if you are touching a powerup first, which stops any other logic being processed. If you are touching a powerup then activate that, if you are not touching a powerup then check if you are touching the sprite below.
B
46
S
16
G
77
Posts: 2,159
Reputation: 45,833

Post » Tue Aug 09, 2016 8:54 pm

Might not be the best to do this but you can use the condition "Mouse Click On An Object" put your events based on each object you are selecting. I have been using this so far with objects overlapping and it never selects the bottom object if I click on the top one.
B
19
S
7
Posts: 161
Reputation: 1,751

Post » Wed Aug 10, 2016 9:08 am

Hi cornfl4ke,

try this:

on tap gesture on Your powerup
-> new sub event: powerup -> Pick top instance.

I hope this helps,
Best Regards,
vargazso
B
19
S
4
Posts: 32
Reputation: 1,044

Post » Thu Aug 11, 2016 1:36 pm

plinkie wrote:Do you mean still have them selectable if you were to click/tap on them if a power up is not on top of them? I guess so, because otherwise that doesn't make a lot of sense. You can check to see if you are touching a powerup first, which stops any other logic being processed. If you are touching a powerup then activate that, if you are not touching a powerup then check if you are touching the sprite below.


Yep, essentially that.
I have a series of rooms that can be selected/set active, if a power up will appears on top of a non active room, I want the tap to pick up the power up but not activate the room below. However if the player chooses they could not tap the power up but still activate the room by tapping on it.
I hope that makes sense.

The check to see if the sprite is on top doesn't seem to work sadly (though it could very well be me setting it up wrong).
B
6
S
1
Posts: 19
Reputation: 440

Post » Thu Aug 11, 2016 1:43 pm

How would the player choose what happens on touching a power up+inactive room from a visual perspective?
B
46
S
16
G
77
Posts: 2,159
Reputation: 45,833

Post » Thu Aug 11, 2016 2:02 pm

You could create some "gates" using variables... essentially a simple state machine.

For a dirty example, lets declare a global variable and call it "Room1State"

If a power-up is not overlapping a room -> set Room1State to 0
If a powerup is overlapping a room -> set Room1State to 1

Then just compare the Room1State as part of your conditions when tapping on the object (room or powerup)

[On Touch]
[Room1State=0]
--- Activate room

[On Touch]
[Room1State=1]
--- Collect Power-up
--- Set Room1State to 0

So when the powerup spawns over a room, just set that variable to 1, or whatever substitute.

This would perhaps work best as an instance variable for your room object, but it depends how you're defining what a "room" is.

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
83
S
34
G
40
Posts: 3,032
Reputation: 30,474

Post » Fri Aug 12, 2016 8:19 am

It's probably my bad explanation, sorry guys.
I'll try and explain best I can.

Imagine a top down view of a building (including garden around it) where you can tap on a room to set it to active to kill monsters that are trying to get into that room from the garden. The idea being you have to chose carefully which room you want active when others could be under attack as you can only have one room active at a time, so keeping the chosen room as active is really important.
Now, randomly spawning anywhere on the map are power ups that the player can store and use in emergencies. They tap on these, the sprite disappears and their power up total gets increased. They can then tap on the use power up button and apply it to whereever they see fit.

The problem is, when a power up appears over the top of an inactive room if the player taps the power up to collect it it also activates that inactive room, which spoils the game horribly if you've set a certain room active to defend the house. Flip side is I still want the player to be able to select that or any other inactive room, which means disabling room selection isn't an option. This is cause sometimes you need to activate a room first before collecting the power up when under pressure (or to not collect the power up at all if you've reached the power up storage limit).

I think that should all make sense :)
Thanks!!
B
6
S
1
Posts: 19
Reputation: 440

Post » Fri Aug 12, 2016 8:22 am

cornfl4ke wrote:It's probably my bad explanation, sorry guys.
I'll try and explain best I can.

Imagine a top down view of a building (including garden around it) where you can tap on a room to set it to active to kill monsters that are trying to get into that room from the garden. The idea being you have to chose carefully which room you want active when others could be under attack as you can only have one room active at a time, so keeping the chosen room as active is really important.
Now, randomly spawning anywhere on the map are power ups that the player can store and use in emergencies. They tap on these, the sprite disappears and their power up total gets increased. They can then tap on the use power up button and apply it to whereever they see fit.

The problem is, when a power up appears over the top of an inactive room if the player taps the power up to collect it it also activates that inactive room, which spoils the game horribly if you've set a certain room active to defend the house. Flip side is I still want the player to be able to select that or any other inactive room, which means disabling room selection isn't an option. This is cause sometimes you need to activate a room first before collecting the power up when under pressure (or to not collect the power up at all if you've reached the power up storage limit).

I think that should all make sense :)
Thanks!!


What I said above still applies. Making a logic gate or state machine for your room selection would solve your problem. :)

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
83
S
34
G
40
Posts: 3,032
Reputation: 30,474

Post » Fri Aug 12, 2016 8:38 am

I said previously what would it look like visually because your logic means at all times you can do A or B, sometimes youll want to do A instead of B, sometimes youll want to do B instead of A but there is seemingly no way for the player to decide what they want to do. If you tap on an inactive room with a powerup you've not set a priority, you said the player can choose to quickly make the room active if they need to OR choose to select the powerup, so you need to design some way that allows all of these things to happen, it's simple to do with logic, just the game design that needs some work. The first few suggestions on here are based on the fact that the powerup is always the priority, it's always the sprite on top, what you're saying is that there is no priority, the player should be able to make a room active/inactive or pick up a power up so it's down to the design of the game on this one.
B
46
S
16
G
77
Posts: 2,159
Reputation: 45,833

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 26 guests