Hi; my question is simple but i can not solve it. i have 3 steps app. main,scene1,scene2 . i am showing my score on scene2 if i decide to play again i wanna user to press “PLAY” button. but it can not go back scene1. on the other hand scenegroup is not working. Everything is disseapering. i attached my app files below.
Main .lua:
local composer = require "composer" display.setStatusBar( display.HiddenStatusBar ) local background = display.newImageRect( "background.png", 360, 570 ) background.x = display.contentCenterX background.y = display.contentCenterY local widget = require( "widget" ) -- Function to handle button events local function handleButtonEvent( event ) if ( "ended" == event.phase ) then composer.gotoScene( "scene1" ) end end -- Create the widget local buttonplay = widget.newButton( { label = "button", onEvent = handleButtonEvent, emboss = false, -- Properties for a rounded rectangle button shape = "roundedRect", width = 200, height = 40, cornerRadius = 2, fillColor = { default={1,0,0,1}, over={1,0.1,0.7,0.4} }, strokeColor = { default={1,0.4,0,1}, over={0.8,0.8,1,1} }, strokeWidth = 4 } ) buttonplay.x = display.contentCenterX buttonplay.y = display.contentCenterY -- Change the button's label text buttonplay:setLabel( "Play" )
scene1.lua
local composer = require( "composer" ) local scene = composer.newScene() local tapCount = 0 local timeLimit = 3 local currentscore =0 -- Later... local function timerDown() timeLimit = timeLimit-1 timeLeft.text = timeLimit if(timeLimit==0)then currentscore = currentscore + tapCount composer.gotoScene( "scene2", { effect = "fade", time = 800, params = { level="Level 1", score=currentscore } } ) end end timer.performWithDelay(1000,timerDown,timeLimit) local background = display.newImageRect( "background.png", 360, 570 ) background.x = display.contentCenterX background.y = display.contentCenterY local platform = display.newImageRect( "platform.png", 300, 50 ) platform.x = display.contentCenterX platform.y = display.contentHeight-25 platform.myName="platform" local balloon = display.newImageRect( "balloon.png", 112, 112 ) balloon.x = display.contentCenterX balloon.y = display.contentCenterY balloon.myName="balloon" balloon.alpha = 0.8 local tapText = display.newText( tapCount, display.contentCenterX, 20, native.systemFont, 40 ) tapText:setFillColor( 0, 0, 0 ) timeLeft = display.newText("Time", display.contentCenterX+100,display.contentCenterY-250,native.systemFont, 20) timeLeft:setTextColor(255,0,0) local physics = require( "physics" ) physics.start() physics.addBody( platform, "static" ) physics.addBody( balloon, "dynamic", { radius=50, bounce=0.3 } ) local function pushBalloon() balloon:applyLinearImpulse( 0, -0.75, balloon.x, balloon.y ) tapCount = tapCount + 1 tapText.text = tapCount print("%s","%d", "currenscore: ", tapCount) end local function onCollision( event ) if(event.object2.myName == "balloon" and event.object1.myName == "platform") then if(tapCount\>0) then tapCount = tapCount -1 tapText.text = tapCount print("%s","%d", "currenscore: ", tapCount) end end end balloon:addEventListener( "tap", pushBalloon ) Runtime:addEventListener( "collision", onCollision ) -- create() function scene:create( event ) local sceneGroup = self.view -- Code here runs when the scene is first created but has not yet appeared on screen print("slm sanırım başardım.") end -- show() function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is still off screen (but is about to come on screen) elseif ( phase == "did" ) then -- Code here runs when the scene is entirely on screen end end -- hide() function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is on screen (but is about to go off screen) elseif ( phase == "did" ) then -- Code here runs immediately after the scene goes entirely off screen end end -- destroy() function scene:destroy( event ) local sceneGroup = self.view -- Code here runs prior to the removal of scene's view end -- ----------------------------------------------------------------------------------- -- Scene event function listeners -- ----------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ----------------------------------------------------------------------------------- return scene
scene2.lua ( PLAY AGAIN IS NOT WORKING.) Actually i can not use sceneGroup
local composer = require( "composer" ) local scene = composer.newScene() -- show() function scene:show( event ) local sceneGroup = self.view local params = event.params local background = display.newImageRect( "background.png", 360, 570 ) background.x = display.contentCenterX background.y = display.contentCenterY local myText = display.newText( params.score, 100, 200, native.systemFont, 16 ) myText:setFillColor( 1, 0, 0 ) --sceneGroup:insert(myText) local widget = require("widget") local bottomTabButtons ={ { width=32, height=32, defaultFile="play.png", overFile="playhover.png", onPress=function() composer.gotoScene( "scene1" ) end}, { width=32, height=32, defaultFile="quit.png", overFile="quithover.png", onPress=function() composer.gotoScene( "scene1" ) end}, } local bottomBar = widget.newTabBar{ top = display.contentHeight-40, buttons = bottomTabButtons } --sceneGroup:insert(background) --sceneGroup:insert(myText) --sceneGroup:insert(bottomBar) end -- hide() function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is on screen (but is about to go off screen) elseif ( phase == "did" ) then -- Code here runs immediately after the scene goes entirely off screen end end -- destroy() function scene:destroy( event ) local sceneGroup = self.view -- Code here runs prior to the removal of scene's view end -- ----------------------------------------------------------------------------------- -- Scene event function listeners -- ----------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ----------------------------------------------------------------------------------- return scene