How do I prevent click through

0 favourites
From the Asset Store
High quality sound effect pack, in the following categories: Simple, negative, pozitive
  • 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?

  • 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.

  • 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.

  • Hi cornfl4ke,

    try this:

    on tap gesture on Your powerup

    -> new sub event: powerup -> Pick top instance.

    I hope this helps,

    Best Regards,

    vargazso

  • 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).

  • How would the player choose what happens on touching a power up+inactive room from a visual perspective?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

  • 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!!

  • 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

  • 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.

  • With a state machine you can jump to any portion of the sate machine you want.

    Using my dirty-example above all you need to do is have a couple of extra conditions on the state change like;

    [On Touch]

    [Room1State=0]

    --- Activate room

    [On Touch]

    [Room1State=1]

    [Touch is on power-up object]

    --- Collect Power-up

    --- Set Room1State to 0

    [ELSE]

    --- Set Room1State to 0

    I guess my pseudo code isn't exactly accurate to your specific circumstance, but it would be the method that I would use if I were trying to achieve what you're trying to build.

    Basically by having a state machine - and comparing the touch position (is it within X distance to the powerup) you can control which "thing" the player is actually touching on. You may also find this can be solved by making the bounding collision box of your power-ups larger - because from memory, it shouldn't "click through" anyway - but it's been a million years since I've made anything for a touch device (so I wouldn't go by my terrible memory of things).

    Think of the state/gate system as a fail-safe. If the power-up exists in a room then the state is 1... but if the player presses on the room and the power-up coordinates are far away from the touch position, then set state to 0 and the player is activating the room itself, otherwise it stays as 1 and collects the power-up then goes to 0.

    I hope this makes it a little clearer.

    ~Sol

  • On touch "Room"

    .. Sub event "Is touching PowerUP"

    .. ... Actions regarding the PowerUP, not considering to activate the room.

    .. Sub event Else, "Is not touching PowerUP"

    .. ... Actions to activate the room without dealing with the power up at all.

    Simplest way to handle it with the plugin Touch I think.

  • Thanks guys! I'll give it a go

  • Hey cornfl4ke,

    edit: I just noticed that I hadn't seen that there was a page 2 for this post with some existing answers. Well here's another then...

    If I understand correctly, it sounds like you want to arrange for the following:

    1. A player can always pick up an item by tapping it.

    2. A single tap that picks up an item won't activate a room.

    3. If an item is sitting somewhere on a room , the player should be able to tap anywhere else on that room to activate the room without picking up the item.

    Just to clarify #3, given a room with an item sitting on the northern half, a player should be able to tap the southern half of the room to activate the room without "touching" the item.

    So, when the user taps,

    you first check if the tap was on an item, and if it was, you then run the item pickup actions.

    Or ELSE, (if the tap was NOT on an item),

    then check if the tap was on a room, and if it was, you then run the room activation actions.

    The events would look like this.

    • - On touch:
      • - Is touching object (item):
        • (Place the actions for touching an item here.)
      • - ELSE - Is touching object (room):
        • (Place the actions for touching a room here.)

    Note that the "ELSE" and the "Is touching object (room)", are two conditions together in the same event.

    To create an "ELSE" condition, select an event and press X to create an ELSE below it.

    Or, right click an event (a whole event not just a condition) and choose Add > Add Else.

    Hope that helps out.

  • Just use 'else', thats why it is for.

    New top-level event ...

    Condition > on powerup clocked

    .....................do all the stuff you need

    New top-level event ...

    Condition > on house clicked

    .....................do all the stuff you need

    For me (personal) this a bit of a PITA. I have troubles reading this code and they need to stay a pair when i start moving events arround. So i usaly do ...

    New EMPTY top-level event

    ....Sub event with the conditions ...

    ....Condition > on powerup clocked

    .....................do all the stuff you need

    ....Sub event with the conditions ...

    ....Condition > on house clicked

    .....................do all the stuff you need

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)