Hello, I am trying to create an UI that slides from top of the screen when pause button is tapped (event listener on pause button calls “showUpperUI” function) and hide the UI, when play button is tapped. Transiton in “showUpperUI” function works fine, but when I press “playButton” to hide the UI, then the playButton display object somehow duplicates. One stays on its position and the second gets trasitioned (as shown on picture).
Here is the code.
local function hideUpperUIAfterAnimation ( event ) pauseButton.isVisible = true --display.remove( playButton ) end local function hideUpperUI( event ) transition.to( playButton, { time=800, alpha=1, x=map.designedWidth/2 + 150, y=-100, onComplete=hideUpperUIAfterAnimation } ) end local function showUpperUIAfterAnimation ( event ) playButton:addEventListener( "tap", hideUpperUI ) print("something") end local function showUpperUI( event ) pauseButton.isVisible = false playButton = display.newImageRect( uiGroup, "texture/ui/play.PNG", 80 ,80 ) playButton.x = map.designedWidth/2 + 150 playButton.y = -85 playButton.alpha = 0.2 transition.to( playButton, { time=800, alpha=1, x=map.designedWidth/2 + 150, y=10, onComplete=showUpperUIAfterAnimation } ) end
Text in “showUpperUIAfterAnimation” function is also printed twice and I dont know why.
I will be grateful for any advice.
I am creating so many functions, because for example I dont want to add event listener to play button while it is being transitioned. Is there a better way to achieve this?
Thank you in advance.