Hi Rob trying physics stop but something not quite right, when moving from scene to scene I think some objects are not removing?
Any chance you could have a look? Would really appreciate it.
--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* -- -- Level1.lua -- --\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* --\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* --Requires-- --\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* local storyboard = require( "storyboard" ) local scene = storyboard.newScene() storyboard.purgeScene( "menu" ) storyboard.purgeScene( "levels" ) local physics = require "physics" physics.start() local widget = require "widget" --Create a function to handle all of the system events local onSystem = function( event ) if event.type == "applicationStart" then print("Application Start") elseif event.type == "applicationExit" then print("Application Exit") elseif event.type == "applicationSuspend" then print("Application Suspended") elseif event.type == "applicationResume" then print("Application Resumed") end end --\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* --Varibales --\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* local score = 0 -- Set Score to 10 local lives = 3 -- Set Lives to 3 local message = "" local playerInAir = true -- Set a boolean of whether our dog is in the air or not --Add sound --local fuel\_cell = audio.loadSound("sound/fuelcell.wav") -- Set sound variable --local life\_lost = audio.loadSound("sound/lifelost.wav") -- Set sound variable --local gameOverScreen = audio.loadSound("sound/game-over.wav") -- Set sound variable --local missionComplete = audio.loadSound("sound/missoncomplete.wav") --\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* --BEGINNING OF GAME IMPLEMENTATION --\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* -- Called when the scene's view does not exist: function scene:createScene( event ) local screenGroup = self.view --------------------------------------------------------------------------------- --Add Rain --------------------------------------------------------------------------------- --[[group = display.newGroup() local g = graphics.newGradient( { 100, 100, 100 }, { 100, 100, 100 }, "down" ) --local bg = display.newRect( 0, 0, screenW, screenH) --bg:setFillColor( g ) --bg.alpha = 0.5 --group:insert(bg) local rain = require("rain") rain.new(group, {}) --Pause rain: --rain.pause() --Resume rain: rain.resume()--]] --------------------------------------------------------------------------------- --End Rain --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- -- Add Ceiling --------------------------------------------------------------------------------- --local ceiling = display.newRect(0,-5,960,5) --physics.addBody( ceiling, "static") --group:insert( ceiling ) --------------------------------------------------------------------------------- -- --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- --Add Backgrounds --------------------------------------------------------------------------------- local background = display.newImage("images/game/background.png") screenGroup:insert(background) background1 = display.newImage("images/game/background-1.png") background1:setReferencePoint(display.BottomLeftReferencePoint) background1.x = 0 background1.y = 320 background1.speed = 0.1 screenGroup:insert(background1) background2 = display.newImage("images/game/background-2.png") background2:setReferencePoint(display.BottomLeftReferencePoint) background2.x = 480 background2.y = 320 background2.speed = 0.1 screenGroup:insert(background2) landscapeback1 = display.newImage("images/game/landscape-back-1.png") landscapeback1:setReferencePoint(display.BottomLeftReferencePoint) landscapeback1.x = 0 landscapeback1.y = 320 landscapeback1.speed = 0.2 screenGroup:insert(landscapeback1) landscapeback2 = display.newImage("images/game/landscape-back-2.png") landscapeback2:setReferencePoint(display.BottomLeftReferencePoint) landscapeback2.x = 480 landscapeback2.y = 320 landscapeback2.speed = 0.2 screenGroup:insert(landscapeback2) landscapefront1 = display.newImage("images/game/landscape-front-1.png") landscapefront1:setReferencePoint(display.BottomLeftReferencePoint) landscapefront1.x = 0 landscapefront1.y = 320 landscapefront1.speed = 0.8 screenGroup:insert(landscapefront1) landscapefront2 = display.newImage("images/game/landscape-front-2.png") landscapefront2:setReferencePoint(display.BottomLeftReferencePoint) landscapefront2.x = 480 landscapefront2.y = 320 landscapefront2.speed = 0.8 screenGroup:insert(landscapefront2) floor1 = display.newImage("images/game/floorLargeBlue.png") floor1:setReferencePoint(display.BottomLeftReferencePoint) floor1.x = 0 floor1.y = 320 floor1.speed = 1.0 physics.addBody( floor1, "static") floor1.myName = "floor" --for collision screenGroup:insert(floor1) floor2 = display.newImage("images/game/floorLargeBlue.png") floor2:setReferencePoint(display.BottomLeftReferencePoint) floor2.x = 480 floor2.y = 320 floor2.speed = 1.0 physics.addBody( floor2, "static") floor2.myName = "floor" --for collision screenGroup:insert(floor2) --platform1 = display.newImage("images/game/platformLarge.png") --platform1:setReferencePoint(display.BottomLeftReferencePoint) --platform1.x = 500 --platform1.y = 200 --platform1.speed = 1.0 --physics.addBody( platform1, "static") --screenGroup:insert(platform1) --platform2 = display.newImage("images/game/platformMed.png") --platform2:setReferencePoint(display.BottomLeftReferencePoint) --platform2.x = 1000 --platform2.y = 150 --platform2.speed = 1.0 --physics.addBody( platform2, "static") --screenGroup:insert(platform2) --------------------------------------------------------------------------------- --Scroll Backgrounds --------------------------------------------------------------------------------- function scrollBackground(self,event) if self.x \< -477 then self.x = 480 else self.x = self.x - self.speed end end --------------------------------------------------------------------------------- --End Backgrounds --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- -- Add Plant Enimies --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- -- Add Alien Plant 1 --------------------------------------------------------------------------------- local function onTimer( event ) local obj = event.source.objectID obj:setLinearVelocity( -30, 0 ) --speed end local AlienPlant = display.newImage( "images/game/alien-plant-large.png" ) AlienPlant.x = 700 --off screen AlienPlant.y = 236 --on floor physics.addBody( AlienPlant, "kinematic" ) AlienPlant:setLinearVelocity( 0, 0 ) AlienPlant.myName = "AlienPlant" --for collision local t = timer.performWithDelay( 250, onTimer ) ; t.objectID = AlienPlant --timer screenGroup:insert(AlienPlant) --------------------------------------------------------------------------------- -- Add Alien Plant 2 --------------------------------------------------------------------------------- local function onTimer( event ) local obj = event.source.objectID obj:setLinearVelocity( -30, 0 ) --speed end local AlienPlant = display.newImage( "images/game/alien-plant-large.png" ) AlienPlant.x = 900 --off screen AlienPlant.y = 236 --on floor physics.addBody( AlienPlant, "kinematic" ) --or "dynamic" interact with object AlienPlant:setLinearVelocity( 0, 0 ) AlienPlant.myName = "AlienPlant" --for collision local t = timer.performWithDelay( 2000, onTimer ) ; t.objectID = AlienPlant --timer screenGroup:insert(AlienPlant) --------------------------------------------------------------------------------- -- Add Alien Plant Small --------------------------------------------------------------------------------- local function onTimer( event ) local obj = event.source.objectID obj:setLinearVelocity( -30, 0 ) --speed end local AlienPlant = display.newImage( "images/game/alien-plant-small.png" ) AlienPlant.x = 500 --off screen AlienPlant.y = 251 --on floor physics.addBody( AlienPlant, "kinematic" ) --or "dynamic" interact with object AlienPlant:setLinearVelocity( 0, 0 ) AlienPlant.myName = "AlienPlant" --for collision local t = timer.performWithDelay( 2000, onTimer ) ; t.objectID = AlienPlant --timer screenGroup:insert(AlienPlant) --------------------------------------------------------------------------------- --End Plant Enimies --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- -- Add Platforms --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- -- Add Platform 1 --------------------------------------------------------------------------------- local function onTimer( event ) local obj = event.source.objectID obj:setLinearVelocity( -30, 0 ) --speed end local platform1 = display.newImage( "images/game/platformLarge.png" ) platform1.x = 500 --off screen platform1.y = 200 --from floor physics.addBody( platform1 , "kinematic" ) --or "dynamic" interact with object platform1:setLinearVelocity( 0, 0 ) local t = timer.performWithDelay( 2000, onTimer ) ; t.objectID = platform1 --timer screenGroup:insert(platform1) --------------------------------------------------------------------------------- -- Add Platform 2 --------------------------------------------------------------------------------- local function onTimer( event ) local obj = event.source.objectID obj:setLinearVelocity( -30, 0 ) --speed end local platform2 = display.newImage( "images/game/platformMed.png" ) platform2.x = 500--off screen platform2.y = 100 --from floor physics.addBody( platform2 , "kinematic" ) --or "dynamic" interact with object platform2:setLinearVelocity( 0, 0 ) local t = timer.performWithDelay( 2000, onTimer ) ; t.objectID = platform2 --timer screenGroup:insert(platform2) -- Add Alien Plant to Platform 2 local function onTimer( event ) local obj = event.source.objectID obj:setLinearVelocity( -30, 0 ) --speed end local AlienPlant = display.newImage( "images/game/alien-plant-small.png" ) AlienPlant.x = 520 --off screen AlienPlant.y = 60 --on floor physics.addBody( AlienPlant, "kinematic" ) --or "dynamic" interact with object AlienPlant:setLinearVelocity( 0, 0 ) AlienPlant.myName = "AlienPlant" --for collision local t = timer.performWithDelay( 2000, onTimer ) ; t.objectID = AlienPlant --timer screenGroup:insert(AlienPlant) --------------------------------------------------------------------------------- -- End Platforms --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- -- Add Character Altazar to Game --------------------------------------------------------------------------------- --Altazar Running Sprite local sheetOptions= { width=70, height=49, numFrames=9, sheetContentWidth=210, sheetContentHeight=147 } myLeftImageSheet = graphics.newImageSheet("images/game/dog-final-right.png", sheetOptions ) myRightImageSheet = graphics.newImageSheet("images/game/dog-final-left.png", sheetOptions ) myJumpRightImageSheet = graphics.newImageSheet( "images/game/dog-final-jump-left.png", sheetOptions) local sequenceData = { { name="leftRightRun", start=1, sheet=myLeftImageSheet, count=9, time = 1100}, --, loopCount = 2 { name="upJumpright", sheet= myJumpRightImageSheet, frames= {1,2,3,4,5,6,7,8,9}, time = 1100}, --, loopCount = 4 { name="rightLeftRun", sheet= myRightImageSheet, frames= {1,2,3,4,5,6,7,8,9}, time = 1100}, --loopCount = 2 } --now build the sprite to hold them and place it on the screen local dogAnimation = display.newSprite( myLeftImageSheet, sequenceData ) dogAnimation.x = screenW / 2 --enter 5 to position slightly of screen --the sprite position horizontally dogAnimation.y = screenH / 2 --the sprite position vertically --add physics physics.addBody( dogAnimation, "dynamic", { density=0.9, friction=0.5, bounce=0 } ) dogAnimation:setLinearVelocity(0,-20)-- change the velocity of the rigid body --dogAnimation:applyForce (100,100,100,100) --physics.setGravity (0.2, 0.2) dogAnimation.isFixedRotation = true dogAnimation.myName = "dogAnimation" --for collision --play spritesheet dogAnimation:play() --dogAnimation:pause() screenGroup:insert(dogAnimation) --------------------------------------------------------------------------------- -- End Alatazar --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- -- Add Enimies CAT and BIRD to Game --------------------------------------------------------------------------------- --Cat Running Sprite local sheetOptions= { width=100, height=70, numFrames=9, sheetContentWidth=300, sheetContentHeight=210 } --now use the options table to build 2 imageSheets- one for lright running --and the other for rleft running myCatImageSheet = graphics.newImageSheet("images/game/cat-final-left.png", sheetOptions ) -- add multiple sequences from these different sheets with different frame counts (for fast/slow) local sequenceData = { { name="catRight", start=1, sheet= myLeftImageSheet, count=9, time = 700,}, --, loopCount = 2 } --now build the sprite to hold them and place it on the screen local catAnimation = display.newSprite( myCatImageSheet, sequenceData ) catAnimation.x = 200--the sprite position horizontally catAnimation.y = screenH / 2 --the sprite position vertically --add physics physics.addBody( catAnimation, "dynamic", { density=0.2, friction=0.2, bounce=0.2 } ) --catAnimation:setLinearVelocity(300,100)-- change the velocity of the rigid body --catAnimation:applyForce (100,100,100,100) --physics.setGravity (0.2, 0.2) catAnimation.isFixedRotation = true catAnimation.myName = "catAnimation" --for collision --move cat catAnimation:translate(1000, -200) -- -200 above top of screen 400 left of screen transition.to(catAnimation, {x = -800, time = 10000}) --x = -800 run off screen to left --y = 200 --alpha = 0, catAnimation:play() --catAnimation:pause() screenGroup:insert(catAnimation) --Bird Running Sprite local sheetOptions= { width=100, height=70, numFrames=5, sheetContentWidth=300, sheetContentHeight=140 } --now use the options table to build 2 imageSheets- one for lright running --and the other for rleft running --now use the options table to build 2 imageSheets- one for lright running --and the other for rleft running myBirdImageSheet = graphics.newImageSheet("images/game/bird-final-right.png", sheetOptions ) -- add multiple sequences from these different sheets with different frame counts (for fast/slow) local sequenceData = { { name="birdFlyingRight", start=1, sheet= myLeftImageSheet, count=5, time = 700}, --, loopCount = 2 { name="birdFlyingRight", sheet= myBirdImageSheet, frames= {1,2,3,4,5}, time = 250}, --, loopCount = 4 --, loopDirection = bounce } --now build the sprite to hold them and place it on the screen local birdAnimation = display.newSprite( myBirdImageSheet, sequenceData ) birdAnimation.x = -200--the sprite position horizontally birdAnimation.y = 160 --the sprite position vertically birdAnimation.rotation = 0 birdAnimation.myName = "birdAnimation" --for collision --move bird birdAnimation:translate(birdAnimation.width/2 , -110) transition.to(birdAnimation, {x = 700, time = 20000}) --y = 200 --alpha = 0, --add physics physics.addBody( birdAnimation, "kinematic") --birdAnimation:setLinearVelocity(300,100)-- change the velocity of the rigid body --birdAnimation:applyForce (100,100,100,100) --physics.setGravity (0.2, 0.2) --play spritesheet birdAnimation:play() --birdAnimation:pause() screenGroup:insert(birdAnimation) --------------------------------------------------------------------------------- -- --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- -- Add Buttons --------------------------------------------------------------------------------- ---Control Alatazar Button functions local function buttonTouch(event) --take in the event and get the associated display object local buttonObj = event.target --now find out which button it is local nameString = buttonObj.id -- define a variable for the final x coordinate of the transition local finalX = dogAnimation.width/2 -- remember registration point is half way! --define another variable for the sequence to play, default left to right local spriteSequence = "leftRightRun" --now use a conditional to set left/right bounds for the transition --and also the animation sequence to load if nameString == "leftButton" then finalX = dogAnimation.width/2 -- default to left spriteSequence = "rightLeftRun" elseif nameString == "rightButton" then finalX = display.contentWidth - dogAnimation.width/2 -- right hand side of screen spriteSequence = "leftRightRun" elseif nameString == "upButton" then finalX = display.contentWidth - dogAnimation.width/2 -- right hand side of screen spriteSequence = "upJumpright" dogAnimation:applyLinearImpulse(0,-9,-9,0 ) end --with the final x value set (based on the button pressed) --the transition can be called after "began" phase if event.phase == "began" then --call the transition, now with added easing! transition.to(dogAnimation, {x = finalX, transition = easing.inCirc, time = 3000}) --was .outExpo 18000 --also load the relevant animation sequence and play it dogAnimation:setSequence( spriteSequence ) dogAnimation:play() elseif event.phase == "ended" then end --remember the issue with event propagation! return true end ---Control Alatazar Buttons --left button widget local leftButton = widget.newButton { defaultFile = "images/HUD\_ui/backDefault.png", overFile = "images/HUD\_ui/backOver.png", id = "leftButton", --id is unique and essential when using event handlers (see below) width = 64, height = 64, onEvent = buttonTouch, } screenGroup:insert(leftButton) --rightbutton widget local rightButton = widget.newButton{ id = "rightButton", --id is again unique defaultFile = "images/HUD\_ui/forwardDefault.png", overFile = "images/HUD\_ui/forwardOver.png", width = 64, height = 64, onEvent = buttonTouch, } screenGroup:insert(rightButton) --upbutton widget local upButton = widget.newButton{ id = "upButton", --id is again unique defaultFile = "images/HUD\_ui/upDefault.png", overFile = "images/HUD\_ui/upOver.png", width = 64, height = 64, onEvent = buttonTouch, } screenGroup:insert(upButton) ---HUD Buttons --pausebutton widget local pauseButton = widget.newButton{ id = "pauseButton", --id is again unique defaultFile = "images/HUD\_ui/pauseDefault.png", overFile = "images/HUD\_ui/pauseOver.png", width = 30, height = 30, --onEvent = buttonTouch, } screenGroup:insert(pauseButton) --resetbutton widget local resetButton = widget.newButton{ id = "resetButton", --id is again unique defaultFile = "images/HUD\_ui/resetDefault.png", overFile = "images/HUD\_ui/resetOver.png", width = 30, height = 30, onEvent = changeScene } screenGroup:insert(resetButton) --Positioning buttons leftButton.y = display.contentHeight - leftButton.height/2 rightButton.x = 120 rightButton.y = display.contentHeight - rightButton.height/2 upButton.x = display.contentWidth - rightButton.width/2 upButton.y = display.contentHeight - rightButton.height/2 --HUD pauseButton.x = screenW-460 pauseButton.y = 20 resetButton.x = 460 resetButton.y = 20 --------------------------------------------------------------------------------- -- --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- -- Add HUD Score and Lives --------------------------------------------------------------------------------- --Add Score to Screen local playerScore = display.newText("Score: "..score, 20, 10, native.systemFont, 15); playerScore:setTextColor(255, 255, 255); playerScore.x = screenW / 2 --playerScore.y = display.contentHeight / 2 screenGroup:insert(playerScore) --Add lives to Screen local playerLives = display.newText("Lives: "..lives, 20, 10, native.systemFont, 15); playerLives:setTextColor(0, 119, 112); playerLives.x = 320 --playerLives.y = display.contentHeight / 2 screenGroup:insert(playerLives) --------------------------------------------------------------------------------- -- --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- -- Add Collisions --------------------------------------------------------------------------------- --Fuel Cell collision -- Detect whether the player is in the air or not function onCollision( event ) -- If guy is touching grass, allow jump if(event.object1.myName == "floor" and event.object2.myName == "dogAnimation") then playerInAir = false end -- Remove coin when it reaches the ground if(event.object1.myName == "floor" and event.object2.myName == "coin") then event.object2:removeSelf() end -- If dog collides with coin, remove coin if(event.object1.myName == "dogAnimation" and event.object2.myName == "coin") then CalcScore() event.object2:removeSelf() end -- If dog collides with AlienPlant, = lose a life if(event.object1.myName == "AlienPlant" and event.object2.myName == "dogAnimation") then CalcLife() end --If dog collides with cat, = lose a life if(event.object1.myName == "dogAnimation" and event.object2.myName == "catAnimation") then CalcLife() end --If dog collides with bird, = lose a life if(event.object1.myName == "dogAnimation" and event.object2.myName == "birdAnimation") then CalcLife() end end Runtime:addEventListener( "collision", onCollision ) --------------------------------------------------------------------------------- -- Add fuel cells --------------------------------------------------------------------------------- function createFuelCell() local coin = { "images/game/fuel-cell.png",} local coin = display.newImage(coin[math.random(1, #coin)], math.random(20,screenW-20), -25, math.random(8,14), math.random(210,223),7) coin.rotation = math.random(0, 90) physics.addBody( coin, "dynamic") --coin.gravityScale = .5 coin.myName = "coin" end timer.performWithDelay( 5000, createFuelCell, 0) --1000 equals time --------------------------------------------------------------------------------- -- --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- -- Add Calclate Score --------------------------------------------------------------------------------- function CalcScore() if (score \<= 1 ) then score = score +1 playerScore.text = "Score: " .. score --audio.play(fuel\_cell) else nextLevel() end end function nextLevel() --audio.play(missionComplete) messageBackground = display.newRect(960, 960, 960, 960) messageBackground:setFillColor(57, 72, 86) messageBackground.x = screenW / 2 messageBackground.y = screenH / 2 messageText= display.newText("MISSION COMPLETE", 20, 10, native.systemFont, 40) messageText.x = screenW / 2 messageText.y = screenH / 2 backButton = display.newImage("images/HUD\_ui/backOver.png") backButton.x = 250 backButton.y = 50 physics.pause( ) --audio.stop(2) --stop audio rain channel=2 end --------------------------------------------------------------------------------- -- --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- -- Add Calclate Lives --------------------------------------------------------------------------------- function CalcLife() if (lives \> 0) then lives = lives -1 if (lives \> 0) then playerLives.text = "Lives: " .. lives --audio.play(life\_lost) else endGame() end else endGame() end end function endGame() storyboard.gotoScene("restart", "fade", 500) --audio.play(gameOverScreen) --messageBackground = display.newRect(960, 960, 960, 960) --messageBackground:setFillColor(57, 72, 86) --messageBackground.x = screenW / 2 --messageBackground.y = screenH / 2 --messageText= display.newText("GAME OVER", 20, 10, native.systemFont, 70) --messageText.x = screenW / 2 --messageText.y = screenH / 2 physics.pause( ) --audio.stop(2) --stop audio rain channel=2 return true end --------------------------------------------------------------------------------- -- --------------------------------------------------------------------------------- end --end create scene -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view background1.enterFrame = scrollBackground Runtime:addEventListener("enterFrame", background1) background2.enterFrame = scrollBackground Runtime:addEventListener("enterFrame", background2) landscapeback1.enterFrame = scrollBackground Runtime:addEventListener("enterFrame", landscapeback1) landscapeback2.enterFrame = scrollBackground Runtime:addEventListener("enterFrame", landscapeback2) landscapefront1.enterFrame = scrollBackground Runtime:addEventListener("enterFrame", landscapefront1) landscapefront2.enterFrame = scrollBackground Runtime:addEventListener("enterFrame", landscapefront2) floor1.enterFrame = scrollBackground Runtime:addEventListener("enterFrame", floor1) floor2.enterFrame = scrollBackground Runtime:addEventListener("enterFrame", floor2) --platform1.enterFrame = scrollBackground --Runtime:addEventListener("enterFrame", platform1) --platform2.enterFrame = scrollBackground --Runtime:addEventListener("enterFrame", platform2) Runtime:addEventListener( "system", onSystem) end --end scene:enterScene -- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view Runtime:removeEventListener("enterFrame", background1) Runtime:removeEventListener("enterFrame", background2) Runtime:removeEventListener("enterFrame", landscapeback1) Runtime:removeEventListener("enterFrame", landscapeback2) Runtime:removeEventListener("enterFrame", landscapefront1) Runtime:removeEventListener("enterFrame", landscapefront2) Runtime:removeEventListener("enterFrame", floor1) Runtime:removeEventListener("enterFrame", floor2) --Runtime:removeEventListener("enterFrame", platform1) --Runtime:removeEventListener("enterFrame", platform2) Runtime:removeEventListener("system", onSystem) storyboard.purgeAll( ) storyboard.removeAll( ) audio.stop(2) --stop audio rain channel=2 physics.pause( ) end --end scene:exitScene -- Called prior to the removal of scene's "view" (display group) function scene:destroyScene( event ) local group = self.view scene:addEventListener("createScene", scene) scene:addEventListener("enterScene", scene) scene:addEventListener("exitScene", scene) scene:addEventListener("destroyScene", scene) end --scene:destroyScene --------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) --------------------------------------------------------------------------------- return scene