How to avoid overlapping "taps"

–image A

I have a transparent image on top (invisible)

so I can swipe my finger an turn pages.

– image B

That image is overlapping with another image

like in another layer.

if I “tap” or “touch” in the place of the image B to do something (show image, play sound…)

the program is detecting the image A, and takes me to another scene, like a swipe.

I use the

“return true”

to prevent the tap from going to the other layers, but it’s not working.

any idea how to fix this?

thanks

You’d need to put the invisible rect at the bottom of the display group, that way you can still detect the other images/objects.
If you have the rect on top of everything else, and it is returning true for touches, then you’ll only detect the rect.

I.W.
if you have something like this:
mainDisplayGroup:insert( imageA )
mainDisplayGroup:insert( imageB )
mainDisplayGroup:insert( invisibleRect )

imageA would be at the bottom of the group and the invisibleRect would be at the top - if it covers the whole screen and is returning true for touch events, it would be the only object that would receive touch events.

It’s generally a good to add your objects in sequence near the bottom of your code.
For example I have this in my code:
 

 

--============================================================================== -------------------------------------------------------------------------------  levelGroup:insert( transRect ) --1st object added to my display group  levelGroup:insert( LeftStick ) --2nd object added, but it is placed Above transRect levelGroup:insert( PTMBtn ) --3rd object added, a button, and is above the joystick levelGroup:insert( Pcross ) -- etc... etc...  levelGroup:insert( JStext ) levelGroup:insert( PTtext )  levelGroup:insert( UTtext )  levelGroup:insert( TXtext )  levelGroup:insert( TYtext )  levelGroup:insert( WMbgi ) levelGroup:insert( pHUD ) levelGroup:insert( pauseBtn ) levelGroup:insert( PopupMenugroup ) levelGroup:insert( transRect ) --[[^^ this ^^ if I added my transRect at the end like this, it would be at the top of the display-group and since it covers the whole screen and has 'return true' in its function, then I would not be able to touch my other objects - joystick, buttons etc.. - because they would technically be behind my invisible rectangle. --]]   Just remember that it's backwards to what you might think: group:insert( object1 ) -- Bottom of display-group group:insert( object2 ) -- Above object1 group:insert( object3 ) -- Above object1 and object2

Now you can also see I have my ‘LeftStick’ (just a joystick) being added to the my level display-group After the transRect. You might think that since the transRect was added first that it would be at the “top layer”, but actually it is at the bottom.

If I did this:
levelGroup:insert( LeftStick )
levelGroup:insert( transRect )

LeftStick is now at the bottom and since my invisible rectangle covers the entire display and returns true in its touch function, then I would not be able to use my joystick because it is Behind my invisible rectangle.

Hope this helped.

-Saer

Edit: Again, all my touch-sensitive objects are added to the main display group *Above my transRect. Otherwise my transRect would be the only object receiving touch events because it covers the whole screen and is returning true.

I read somewhere else about the hierarchy of objects

the numbers 1, 2 ,3 ond so on…

I’m going to study that to really understand it.

I’m reading what you post, 2 or 3 times

right now, but it’s a little bit too much…

Thank you, anyway. I’m going to keep this in mind

maybe in a few weeks or months, I’ll be able to understand that really well

I edited my previous post, removing all the unnecessary info such as the camera etc…
Hopefully it will help you. :slight_smile:

-Saer

You’d need to put the invisible rect at the bottom of the display group, that way you can still detect the other images/objects.
If you have the rect on top of everything else, and it is returning true for touches, then you’ll only detect the rect.

I.W.
if you have something like this:
mainDisplayGroup:insert( imageA )
mainDisplayGroup:insert( imageB )
mainDisplayGroup:insert( invisibleRect )

imageA would be at the bottom of the group and the invisibleRect would be at the top - if it covers the whole screen and is returning true for touch events, it would be the only object that would receive touch events.

It’s generally a good to add your objects in sequence near the bottom of your code.
For example I have this in my code:
 

 

--============================================================================== -------------------------------------------------------------------------------  levelGroup:insert( transRect ) --1st object added to my display group  levelGroup:insert( LeftStick ) --2nd object added, but it is placed Above transRect levelGroup:insert( PTMBtn ) --3rd object added, a button, and is above the joystick levelGroup:insert( Pcross ) -- etc... etc...  levelGroup:insert( JStext ) levelGroup:insert( PTtext )  levelGroup:insert( UTtext )  levelGroup:insert( TXtext )  levelGroup:insert( TYtext )  levelGroup:insert( WMbgi ) levelGroup:insert( pHUD ) levelGroup:insert( pauseBtn ) levelGroup:insert( PopupMenugroup ) levelGroup:insert( transRect ) --[[^^ this ^^ if I added my transRect at the end like this, it would be at the top of the display-group and since it covers the whole screen and has 'return true' in its function, then I would not be able to touch my other objects - joystick, buttons etc.. - because they would technically be behind my invisible rectangle. --]]   Just remember that it's backwards to what you might think: group:insert( object1 ) -- Bottom of display-group group:insert( object2 ) -- Above object1 group:insert( object3 ) -- Above object1 and object2

Now you can also see I have my ‘LeftStick’ (just a joystick) being added to the my level display-group After the transRect. You might think that since the transRect was added first that it would be at the “top layer”, but actually it is at the bottom.

If I did this:
levelGroup:insert( LeftStick )
levelGroup:insert( transRect )

LeftStick is now at the bottom and since my invisible rectangle covers the entire display and returns true in its touch function, then I would not be able to use my joystick because it is Behind my invisible rectangle.

Hope this helped.

-Saer

Edit: Again, all my touch-sensitive objects are added to the main display group *Above my transRect. Otherwise my transRect would be the only object receiving touch events because it covers the whole screen and is returning true.

I read somewhere else about the hierarchy of objects

the numbers 1, 2 ,3 ond so on…

I’m going to study that to really understand it.

I’m reading what you post, 2 or 3 times

right now, but it’s a little bit too much…

Thank you, anyway. I’m going to keep this in mind

maybe in a few weeks or months, I’ll be able to understand that really well

I edited my previous post, removing all the unnecessary info such as the camera etc…
Hopefully it will help you. :slight_smile:

-Saer