I'm having a little trouble with transitioning from my menu screen to the next game option.
My menu screen and buttons fade in using transition.to, and when one of the buttons is pressed, I want the background to fade to white, the buttons to fade, and the new scene to load.
I can get the display objects to fade when a button is pressed, but I can't figure out how to make the scene change after my screen fades to white.
I have tried using a timer:performWithDelay but to no avail.
Any ideas?
Some of my code below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | local colorsbtn = display.newImageRect("images/colorbtn.png", 121, 121) colorsbtn:setReferencePoint(display.CenterReferencePoint) colorsbtn.x =440 ; colorsbtn.y=295 colorsbtn.alpha=0 transition.to(colorsbtn, {time=1000, y=295, x=240, alpha=1}) colorsbtn.scene = "colors" local flashbtn = display.newImageRect("images/flashcardbtn.png", 121, 121) flashbtn:setReferencePoint(display.CenterReferencePoint) flashbtn.x =-120 ; flashbtn.y=420 flashbtn.alpha=0 transition.to(flashbtn, {time=1000, y=420, x=80, alpha=1}) flashbtn.scene = "flash" local whiteFadeout = function(event) director:changeScene(e.target.scene) end local function changeScene(e) if(e.phase=="ended" or e.phase=="cancelled")then transition.to(bg_frame, {time=1000, alpha=0}) -- fades out background artwork transition.to(whiteback, {time=500, alpha=1}) -- fades in white background transition.to(flashbtn, {time=1000, alpha=0}) -- fades out flashbtn transition.to(colorsbtn, {time=1000, alpha=0}) -- fades out colorsbtn timer:performWithDelay (1000, whiteFadeout) end end |
It should be timer.performWithDelay, in case that was your issue.
If you want to use director to change scenes with a delay to this;
1 2 3 4 | local function changeScene () director:changeScene("sceneName") end timer.performWithDelay(1000, changeScene, 1) |
views:1451 update:2011/10/26 9:29:31