Prevent click/tap through opaque layer

Get help using Construct 2

Post » Sun Jan 29, 2012 5:26 pm

So guys, I have this Instructions button that makes visible a layer with some text that's placed on top of everything.

The problem is that the user can tap through this opaque layer and activate the (now) invisible buttons (invisible because of the "instructions" layer) on the layers below.

I don't want to create a layout with instructions because I want to keep the layout state.

I'm looking, I think, for sort of a "handled" flag on the mouse event or something...

Any hints?

Thanks.
B
14
S
5
G
7
Posts: 235
Reputation: 5,175

Post » Sun Jan 29, 2012 8:24 pm

Instead of obscuring the objects destroy them or move them out the way, then they won't receive touch/click events. Or, set them invisible with 'Set visible' and add the condition 'Is visible' to any click/touch events.Ashley2012-01-29 20:24:57
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478

Post » Mon Jan 30, 2012 8:08 am

Thanks Ashley - but I was hoping to avoid that (and I did, sort of). I managed to work around it by making the layout bigger and putting the instructions somewhere far off the normal viewport, and then I just scroll to the instructions, and then I scroll back to the game. This has the advantage that if I add something to the main screen, I don't have to remember to add custom stuff to it (hide it, check for visibility etc).

So it's almost what you suggest, moving the objects away, except I didn't move the objects - I moved the thing that was supposed to be on top of them, so they don't overlap.

However I still think that a mechanism to prevent the click or tap from "bubbling further up" (or in other words marking it as Handled) would be nice.

Thanks!
B
14
S
5
G
7
Posts: 235
Reputation: 5,175

Post » Mon Jan 30, 2012 3:55 pm

If you just use the set invisible on an entire layer, you can add stuff to that layer without having to put in anymore "custom" stuff to it.
B
7
Posts: 15
Reputation: 756

Post » Tue Jan 31, 2012 6:07 am

Actually I just did a small test. What you say applies to buttons, but not to sprites (I have sprites instead of buttons on my project).

So if you have a sprite on an invisible layer, it will still get the "on clicked object", making it need custom stuff.
B
14
S
5
G
7
Posts: 235
Reputation: 5,175

Post » Tue Jan 31, 2012 9:10 am

add a boolean 'active' with default true to your sprite buttons

[code]+System: Every Tick
-> Button: set active to true
+System: Layer "yourLayer" is visible
-> Button: set active to 'false'
+Mouse: On left click on Button
+Button is active
-> System: set Layer "yourLayer" to visible[/code]
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346


Return to How do I....?

Who is online

Users browsing this forum: Radulepy, Yahoo [Bot] and 11 guests