hi, it’s my first experience with composer
i can switch between scene but i can’t reload my level 1 to see my circle do again a transition.
below the scheme i want :
> menu >playBtn > level1 > button3 > menu > playBtn > level1(and do the transistion again)
if you could give some advice’s to me…the doc is not easy about this part…
thanks a lot.
-- main.lua ----------------------------------------------------------------------------------------- display.setStatusBar( display.HiddenStatusBar ) local composer = require "composer" composer.gotoScene( "menu" )
menu.lua
----------------------------------------------------------------------------------------- -- -- menu.lua -- ----------------------------------------------------------------------------------------- local composer = require( "composer" ) local scene = composer.newScene() local widget = require "widget" -------------------------------------------- -- forward declarations and other locals local playBtn -- 'onRelease' event listener for playBtn local function onPlayBtnRelease() -- go to level1.lua scene composer.gotoScene( "level1", "fade", 500 ) return true -- indicates successful touch end function scene:create( event ) local sceneGroup = self.view local splash = display.newImageRect("splash.png", 240, 160) splash.x = 240 splash.y = 160 splash.xScale=2 splash.yScale=2 posy=230 sca=1.2 -- create/position logo/title image on upper-half of the screen -- create a widget button (which will loads level1.lua on release) playBtn = widget.newButton{ width = 240, height = 120, label="", labelColor = { default={255}, over={128} }, defaultFile ="play.png", overFile ="playover.png", onRelease = onPlayBtnRelease -- event listener function } playBtn.yScale= 0.5 playBtn.xScale = 0.4 playBtn.x = 300 playBtn.y = 200 -- all display objects must be inserted into group sceneGroup:insert( splash ) sceneGroup:insert( playBtn ) end function scene:show( event ) local sceneGroup = self.view local phase = event.phase if phase == "will" then -- Called when the scene is still off screen and is about to move on screen elseif phase == "did" then -- Called when the scene is now on screen -- -- INSERT code here to make the scene come alive -- e.g. start timers, begin animation, play audio, etc. end end function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if event.phase == "will" then -- Called when the scene is on screen and is about to move off screen -- -- INSERT code here to pause the scene -- e.g. stop timers, stop animation, unload sounds, etc.) elseif phase == "did" then -- Called when the scene is now off screen end end function scene:destroy( event ) local sceneGroup = self.view -- Called prior to the removal of scene's "view" (sceneGroup) -- -- INSERT code here to cleanup the scene -- e.g. remove display objects, remove touch listeners, save state, etc. if playBtn then playBtn:removeSelf() -- widgets must be manually removed playBtn = nil end end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) ----------------------------------------------------------------------------------------- return scene
level1.lua
----------------------------------------------------------------------------------------- -- -- level1.lua -- ----------------------------------------------------------------------------------------- local composer = require( "composer" ) local scene = composer.newScene() -- include Corona's "physics" library local physics = require "physics" physics.start(); physics.pause() local widget = require( "widget" ) -------------------------------------------- function scene:create( event ) local sceneGroup = self.view local function CircleonTransitionAppears() CircleonTransition = display.newImageRect("Pustulle.png", 40, 40) CircleonTransition.x = 240 CircleonTransition.y = 230 CircleonTransition.xScale = 2.8 CircleonTransition.yScale = 2.8 return CircleonTransition end CircleonTransitionAppears() local function transitionToCircle() transition.to(CircleonTransition, {time=300,yScale=1.5, xScale=1.5, alpha=0.01, transition=easing.inOutexpo}) end local function handleButtonEventRestart( event ) if ( "ended" == event.phase ) then composer.gotoScene( "menu" ) end end local button3 = widget.newButton { width = 240, height = 120, defaultFile = "buttoninactif.png", overFile = "buttonpressed.png", label = "button", onEvent = handleButtonEventRestart } -- Center the button button3.x = 240 button3.y = 180 button3.xScale = 0.5 button3.alpha = 1 button3:setLabel( ) timer.performWithDelay( 1000, transitionToCircle ) -- all display objects must be inserted into group sceneGroup:insert( CircleonTransition ) sceneGroup:insert( button3 ) end function scene:show( event ) local sceneGroup = self.view local phase = event.phase if phase == "will" then -- Called when the scene is still off screen and is about to move on screen elseif phase == "did" then -- Called when the scene is now on screen -- INSERT code here to make the scene come alive -- e.g. start timers, begin animation, play audio, etc. physics.start() end end function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if event.phase == "will" then -- Called when the scene is on screen and is about to move off screen -- -- INSERT code here to pause the scene -- e.g. stop timers, stop animation, unload sounds, etc.) physics.stop() elseif phase == "did" then -- Called when the scene is now off screen end end function scene:destroy( event ) -- Called prior to the removal of scene's "view" (sceneGroup) -- INSERT code here to cleanup the scene -- e.g. remove display objects, remove touch listeners, save state, etc. local sceneGroup = self.view package.loaded[physics] = nil physics = nil end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) ----------------------------------------------------------------------------------------- return scene