Discuss Scratch

rdococ
Scratcher
1000+ posts

Detecting touch only when there isn't another sprite in between the two main layers?

I'm updating my OS, but when I put multitasking on, you can click the buttons of the window behind it. I only want the touch (which is with a sprite ‘Pointer’) to be detected when there is no obtruding sprite with a layer in between the two sprites' layers. (PS. It's fine if they overlap a little. Only if the overlap extends to or past the co-ordinates clicked on.)
mwiedmann
Scratcher
100+ posts

Detecting touch only when there isn't another sprite in between the two main layers?

I put together a small demo that show 1 way to manage layers.

Handling Layers

It basically has a global variable to track what is the highest layer number that is currently touching the mouse. Sprites can then check their layer number against this global highest layer number to see if they should respond to a mouse click or other input. I put an extra “LayerState” variable in there so the sprites can ignore input if the highest layer number is currently being calculated. The script seems to work fine without this last part but it may be safer to leave it in.

One thing to note is that you will have to keep track of the layer number for each sprite. You can't just use “go to front” or “go back 1 layer”. That can be difficult but it can be done.

This may give you some ideas. Hope it helps.
dracae
Scratcher
1000+ posts

Detecting touch only when there isn't another sprite in between the two main layers?

mwiedmann wrote:

I put together a small demo that show 1 way to manage layers.

Handling Layers

It basically has a global variable to track what is the highest layer number that is currently touching the mouse. Sprites can then check their layer number against this global highest layer number to see if they should respond to a mouse click or other input. I put an extra “LayerState” variable in there so the sprites can ignore input if the highest layer number is currently being calculated. The script seems to work fine without this last part but it may be safer to leave it in.

One thing to note is that you will have to keep track of the layer number for each sprite. You can't just use “go to front” or “go back 1 layer”. That can be difficult but it can be done.

This may give you some ideas. Hope it helps.

That's pretty clever…
Even though I wasn't the intended recipient, I'm still glad I got this help!
rdococ
Scratcher
1000+ posts

Detecting touch only when there isn't another sprite in between the two main layers?

Nevermind… thanks for the help, but I found a very simple solution. It is to use a WHEN THIS SPRITE CLICKED hat block instead of a FOREVER loop.
Paddle2See
Scratch Team
1000+ posts

Detecting touch only when there isn't another sprite in between the two main layers?

Closed by request of the topic owner.

Powered by DjangoBB