how can I delay the changeScene function?? i want it to change scene a few seconds after the lives hit 0, is there any way i can do this? thanks!
[code]
local function killCrate (event)
crate:removeSelf()
lives = lives - 1
livesDisplay.text = lives
if lives == 0 then
director:changeScene(“level1success”)
end
end
crate:addEventListener(“touch”, killCrate)
[/code] [import]uid: 10827 topic_id: 9635 reply_id: 309635[/import]
you would want to put your changeScene code into a new function. Then you can use what is called a timer. A timer allows you to call a function at a set time. for example
timer.performWithDelay(2000, changeScene, 1 )
this code is saying, after 2 seconds ( or 2000 milliseconds) call the function changeScene, 1 time.
so perhaps you could do this:
local function changeScene()
director:changeScene("level1success")
end
local function killCrate (event)
crate:removeSelf()
lives = lives - 1
livesDisplay.text = lives
if lives == 0 then
timer.performWithDelay(2000, changeScene, 1)
end
end
crate:addEventListener("touch", killCrate)
[import]uid: 19620 topic_id: 9635 reply_id: 35117[/import]
works perfectly! thank you so much! [import]uid: 10827 topic_id: 9635 reply_id: 35125[/import]
no problem, now make an awesome app! =p [import]uid: 19620 topic_id: 9635 reply_id: 35126[/import]