two buttons over each other

Hello!

I am getting something i don’t understand?

if i have two buttons over each other on big and on smaller ontop of the big one, i got a function that checks for a certain button but when i am clicking on the little on who is onto of the big one, the big one also is pressed. How come?

here is an example:

[lua]function ufoMovement(event)

if(event.target.name == “up” and crashed == false) then

if(event.phase == “began”) then

tmrUp = timer.performWithDelay(150, engines, 0)

elseif(event.phase == “ended”) then
timer.cancel(tmrUp)

spriteInstance.linearDamping = 0

end

end

if(event.target.name == “left” and crashed == false) then

if(event.phase == “began”) then

tmrLeft = timer.performWithDelay(200, sideleft, 0)

elseif(event.phase == “ended”) then

timer.cancel(tmrLeft)
end

end
end
buttonUp:addEventListener(“touch”, ufoMovement)
buttonLeft:addEventListener(“touch”, ufoMovement)[/lua]

i have named the buttons with .name like buttonUp.name = “up”

I think i should be able to hit one button and not let the one under it get pressed?

Kind regards

Inkoqnito [import]uid: 90942 topic_id: 16792 reply_id: 316792[/import]

it’s the magic of something called event bubbling. if you handle the event, return true to stop the event from bubbling up.

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 16792 reply_id: 62856[/import]

Jayant!

You are the best!

This thing has haunted me some time, and then it just was two little words “return true” and then my game started to behave like it was supposed to:D

Thanks again!

Take care

/Inkoqnito [import]uid: 90942 topic_id: 16792 reply_id: 62889[/import]

that “return true” is a super line, its very easy to miss, but damn useful [import]uid: 16142 topic_id: 16792 reply_id: 62900[/import]

It truly is! But just so i understod what i am doing? If i return true i tell The program that i have taken care of the event and it wont do any so event bubbling? [import]uid: 90942 topic_id: 16792 reply_id: 62903[/import]

something like that, you tell event to stop propagating [import]uid: 16142 topic_id: 16792 reply_id: 62947[/import]