Touch propagation. I do return true and still not working.

Hi guys, I’m having a really newbie question. I’ve read in tons of places that to avoid this behaviour I just have to return true in the functions that are called by the events, but it’s not working… of course because I’m doing something wrong, but I can’t tell what?! 

I have a background like this: 

local background = display.newRect( centerX, centerY, display.contentWidth, display.contentHeight ) background:setFillColor( 20/255, 21/255, 25/255 ) sceneGroup:insert( background )

I add the following listener: 

function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then elseif ( phase == "did" ) then background:addEventListener( "tap", moveCrocodile ) Runtime:addEventListener( "collision", onCollision ) Runtime:addEventListener( "enterFrame", moveBirds ) end end

And I also have a button that is added on the scene:create like this:

local fastButton = widget.newButton { x = \_W - 149/2, y = \_H - 149/2, width = 149, height = 149, onEvent = changeHeight, defaultFile = "images/height.png", overFile = "images/heightPressed.png" } sceneGroup:insert( fastButton )

The button of course is over the background but when I touch the button the “onEvent” event that calls changeHeight and the moveCrocodile is called as well. I don’t know what else to try. Both of my changeHeight and moveCrocodile are returning true at the end. What can be wrong?!

changeHeight = function ( event ) if event.phase == "began" then elseif event.phase == "ended" then end print("changeSpeed is called") return true end

moveCrocodile = function ( event ) print("moveCrocodile called") return true end

THANKS!!!

It looks like you’re using both “touch” and “tap” together. It’s my understanding that returning true will only keep the event from propagating from one touch listener to another touch listener, or one tap listener to another tap listener. I’m not sure where this is documented.

Try changing your “tap” to “touch”. Then in the function that gets called add code to check for phase and only take action on “ended”. 

Hi @andresyo990,

@elbowroomapps is correct… if you listen for both a tap and a touch, you’ll get both responses, even with a return true. The following tutorial may give you some options to explore, however, specifically in regards of handling both events.

http://www.coronalabs.com/blog/2013/10/01/tutorial-taptouch-anatomy/

Best regards,

Brent

Thanks guys! that tutorial nailed it!

It looks like you’re using both “touch” and “tap” together. It’s my understanding that returning true will only keep the event from propagating from one touch listener to another touch listener, or one tap listener to another tap listener. I’m not sure where this is documented.

Try changing your “tap” to “touch”. Then in the function that gets called add code to check for phase and only take action on “ended”. 

Hi @andresyo990,

@elbowroomapps is correct… if you listen for both a tap and a touch, you’ll get both responses, even with a return true. The following tutorial may give you some options to explore, however, specifically in regards of handling both events.

http://www.coronalabs.com/blog/2013/10/01/tutorial-taptouch-anatomy/

Best regards,

Brent

Thanks guys! that tutorial nailed it!