making a one touch object(i think)(just read please)

i need help with this line(s) of code

 

function touchPLayBtn:tap( event )
transition.to(playBtn,{time=200, x=(display.contentWidth), y=(display.contentHeight), onComplete =function()
touchPlayBtn.isVisible = false
composer.gotoScene(“startgame”, {effect = “fade”, time=700})
})
return true
end
touchPLayBtn:addEventListener( “tap”, touchPLayBtn)

 

 

i have an arrow(playBtn) that flys off screen when touchd but i cant get it to do that with this code i need it to well if i press anywhere on the screen it still flys off i need it to only fly off when the arrow gets touched not the screen 

here is the code that makes it fly off even if you touch anywhere on the screen 

 

function touchPLayBtn(event)

if event.phase == “ended” then

transition.to(playBtn,{time=200, x=400, y=400})

composer.gotoScene(“startgame”, {effect = “fade”, time=700})

 

return true

 

end

end

 

Runtime:addEventListener(“touch”, touchPLayBtn)

 

 

thanks for you time and help.

Can you post some more code? Perhaps your object creation code as well.  It’s best to put it inside and tags (leave out the space after the [ to preserve formatting.

Rob

function touchPLayBtn(event)

if event.phase == “ended” then

transition.to(playBtn,{time=200, x=400, y=400})

composer.gotoScene(“startgame”, {effect = “fade”, time=700})

return true

end

end

Runtime:addEventListener(“touch”, touchPLayBtn)


thats the only code really have to make the arrow move off the screen and onComplete it goes to scene start game but to move the arow i can press anywhere on the screen and the arrow moves and changes scenes but i want it to be like: so if i press somewhere other that the arrow nothing happens so pretty much i want on the arrow to be pressable if that makes any sense so far just ask for anything else. thanks

This is likely the problem:

Runtime:addEventListener(“touch”, touchPLayBtn)

When you use “Runtime” you’re attaching the touch handler to the entire app.  Since you didn’t post the code that creates the arrow, I don’t know what you called it, but normally you would but the touch handler directly on the object:

local playButton = …

local function touchPlayButton( event )

    …

    return true

end

playButton:addEventListener(“touch”, touchPlayButton)

Rob

thank you so much that worked!!!

Can you post some more code? Perhaps your object creation code as well.  It’s best to put it inside and tags (leave out the space after the [ to preserve formatting.

Rob

function touchPLayBtn(event)

if event.phase == “ended” then

transition.to(playBtn,{time=200, x=400, y=400})

composer.gotoScene(“startgame”, {effect = “fade”, time=700})

return true

end

end

Runtime:addEventListener(“touch”, touchPLayBtn)


thats the only code really have to make the arrow move off the screen and onComplete it goes to scene start game but to move the arow i can press anywhere on the screen and the arrow moves and changes scenes but i want it to be like: so if i press somewhere other that the arrow nothing happens so pretty much i want on the arrow to be pressable if that makes any sense so far just ask for anything else. thanks

This is likely the problem:

Runtime:addEventListener(“touch”, touchPLayBtn)

When you use “Runtime” you’re attaching the touch handler to the entire app.  Since you didn’t post the code that creates the arrow, I don’t know what you called it, but normally you would but the touch handler directly on the object:

local playButton = …

local function touchPlayButton( event )

    …

    return true

end

playButton:addEventListener(“touch”, touchPlayButton)

Rob

thank you so much that worked!!!