Hi everyone, I have a project in which I have a png file that I want to display and then show a button using the native.showalert function. However, I want to pause execution while the png file is on the screen. The whole png image is a listener and touching anywhere on the image closes it. My problem is that while all these items work, I cannot pause execution while the png is on the screen. I have tried timers and even a while … do loop which only ends when a flag within the listener gets changed. None of my attepnts work - I’m probably really stupid.
here’s an example:
function display\_test()
display\_destination\_card() -- call the function that displays the card
local alert = native.showAlert( "Message Header", "Well done.", { "Continue" }) -- message that should not be returned to until the showcard image has been touched
end
function display\_destination\_card()
dcardpressed = "N" -- flag
showcard = display.newImageRect("carddisplay.png",400,250)
showcard.x = \_w/2
showcard.y = \_h/2
showcard.alpha = 0
transition.to( showcard, { time=500, delay = 500,alpha=1 }) -- fade the card in
showcard:addEventListener ("touch", presscardcontinue) -- set up the listener
tmr = timer.performWithDelay(200, pause\_game,-1) -- infinite timer
-- I do not want to return from this function until the showcard image has been touched!!
end
function pause\_game()
while dcardpressed ~= "Y" do -- loop
if dcardpressed == "Y" then -- change flag when the event listener has been touched
timer.cancel(tmr); -- cancel timer
break
end
end
end
function presscardcontinue(event)
if event.phase == "ended" then
showcard:removeEventListener ("touch", presscardcontinue)
showcard:removeSelf()
dcardpressed = "Y" -- set flag
return
end
end
What I want to happen is that the display_destination_card() function gets called and then there is no return to the next line (local alert…) until the showcard image has been touched. At the moment, the “local alert” message shows up immediately (I don’t want it to show at all) and the showcard image half shows up behind
the local alert message (presumably halfway through the delay procedure.
Not sure if I’ve explained this correctly - please ask if this doesn’t make sense!
It would be great if there was some function called something like “wait()”.
Please help as its almost the last thing I have to do before my first game is complete!!
Thanks
Adrian [import]uid: 83824 topic_id: 20017 reply_id: 320017[/import]
