Touch event for Newbie

I have a simple game that I’m testing and I’m having a problem with my touch event.  It’s a side-scroller game that has a ship that fires bullets at enemies.  So I have a background image and I’ve added a fire button graphic. When I press the fire button, I’d like my ship to fire a bullet, but when I press anywhere else on the screen, I’d like to just move the ship upwards.  The problem I’m having is that when I touch the fire button it does fire a bullet, but it also moves the ship upwards, which I don’t want.  When I touch the screen without touching the fire button it does behave correctly by just moving the ship upwards.

I have a runtime listener on the touch event, and a regular event listener on the fire button.  Am I suppose to test what part of the screen was touched?  I can’t seem to get this working properly.  Please advise.

Can you post the event listener for the fire button? To prevent touches or taps from passing through layers, you should use “return true” in your event listener. Here’s an example.

local function tapListener( event ) local object = event.target print( object.name.." TAPPED!" ) -- do something here return true --prevent propagation to underlying tap objects end

Thanks James, the Return True did it!

Glad to hear it @hackbrew.

Can you post the event listener for the fire button? To prevent touches or taps from passing through layers, you should use “return true” in your event listener. Here’s an example.

local function tapListener( event ) local object = event.target print( object.name.." TAPPED!" ) -- do something here return true --prevent propagation to underlying tap objects end

Thanks James, the Return True did it!

Glad to hear it @hackbrew.