Why does touch event take place in lower layer not top layer of the screen ?:Need help!

I added touchable objects before I added the floor.
I found that I can touch objects which are behind the floor. I want objects cannot be touch behind the floor.
After test, I found that object which was first added in displayGroup was the first object that got touch event. I do not know how to solve this problem. Just want the touch event only takes place on top layer of the screen.
[import]uid: 65906 topic_id: 16459 reply_id: 316459[/import]

In your function that handles the touch events, are you returning true at the end.

I think you need to do that to keep the touch from propagating to the lower level objects. [import]uid: 67839 topic_id: 16459 reply_id: 61508[/import]

Like the guy said above.

Your function (touch events) will need to look similar to this :

[code]
local function touch(event)

if event.phase == “began” then
print(“Hi”)
end

–Stop touch events registering on images underneath or below the image being touched
return true
end
[/code] [import]uid: 84637 topic_id: 16459 reply_id: 61559[/import]

elbowroomapps and Danny
Thanks for your advice.
I have already tried on “return true” before I made this thread but it did not work. I wonder about display.newGroup()… inserting object in the group is somehow effect on event handler or not? [import]uid: 65906 topic_id: 16459 reply_id: 61578[/import]

Is what you mean that you have whatever object and it is displaying behind the floor and you don’t want it to react to touches while there?

If so, maybe the problem is that your floor isn’t anything - just an image - and so everything behind it can be touched. [import]uid: 52491 topic_id: 16459 reply_id: 61654[/import]

@peach,
my floor has physic body(“static”) + touch event(return true).

That’s why I feel confused why it does not work [import]uid: 65906 topic_id: 16459 reply_id: 61826[/import]

Have you tried just doing everything without groups first, and seeing if that works THEN introducing the different groups?

Also, yea the return true is what you need, but if you have something behind the object you are touching and do NOT want to touch it, you need to return true or you keep propogating the touch event.

At least, that’s the way I’ve tested it and it’s always worked. What you could do is make a VERY basic file with a square, and background and test yourself with the return true vs no return true and you will see it will act differently.

After that, you can sort out the groups or whatever. I always find that I make little “mini feature” prototypes of JUST the feature I want, so I don’t confuse myself :slight_smile:
Just at thought :slight_smile:

ng [import]uid: 61600 topic_id: 16459 reply_id: 61882[/import]

Thank you everyone.
The problem is solved.
I made mistake in group:insert() order.
I add floor before the objects.
But I did not realize because my scene is in “hybrid” mode so it is hard for me to see things clear.

Thank you. [import]uid: 65906 topic_id: 16459 reply_id: 62372[/import]

“Have you tried just doing everything without groups first, and seeing if that works THEN introducing the different groups?”
I see you have discovered your error. :slight_smile:

Remember lua uses the “painters model” meaning that things should be in order in most cases :slight_smile:
Trust me, I’ve been there done that. Still bites me in the ass sometimes these days too! :slight_smile:

ng
[import]uid: 61600 topic_id: 16459 reply_id: 62407[/import]