I am creating a gaming app and when the user goes from the game to the play the next level scene , nothing gets removed . The game scene works ok at times but my real issue is with the play next scene . The walls that I created in game move to the next scene and the background image in the play next scene shows in a little corner . I was using storyboard and this wasn’t happening but when I moved into composer I was getting a lot of issues . Can someone help me to completely remove the scene ? I’ve tried code from my previous composer apps and nothing is helping . I tried showing the error but nothing showed up . This is what I have as of now :
game.lua :
-- requires local physics = require "physics" physics.start() local composer = require( "composer" ) local scene = composer.newScene() function scene:create(event) local screenGroup = self.view local randomImage = math.random(1,41) local background = display.newImageRect("images/background"..randomImage..".jpg",display.contentWidth,display.contentHeight) background.x = display.contentCenterX background.y = display.contentCenterY screenGroup:insert(background) display.setDefault("fillColor", 0, 1, 1) CreateWalls(1) -- create image of a ball Ball = display.newCircle(100, 100, 10) physics.addBody(Ball, "dynamic", {friction=2}) Ball:applyLinearImpulse(-.05, .05, 0, 0) screenGroup:insert(Ball) end function scene:show(event) composer.removeScene( "start" ) Ball:addEventListener( "tap", onBallTap ) end function scene:hide(event) end function scene:destroy(event) end scene:addEventListener("create", scene) scene:addEventListener("show", scene) scene:addEventListener("hide", scene) scene:addEventListener("destroy", scene) return scene
next level scene :
-- requires local composer = require( "composer" ) local scene = composer.newScene() -- background function scene:create(event) local screenGroup = self.view local randomImage = math.random(1,41) local background = display.newImageRect("images/background"..randomImage..".jpg",display.contentWidth,display.contentHeight) background.x = display.contentCenterX background.y = display.contentCenterY screenGroup:insert(background) local restart = display.newText( "Touch Screen to go to next level", display.contentCenterX, display.contentCenterY, native.systemFont, 25 ) screenGroup:insert(restart) end local options = { effect = "flip", time = 400 } local function touchScreen( event ) if event.phase == "began" then composer.removeScene( "restart" ) composer.gotoScene( "game2", options ) end end function scene:show(event) local phase = event.phase if ( phase == "will" ) then print("Phase started") elseif ( phase == "did" ) then print("phase showing objects") composer.removeScene( "game" ) end Runtime:addEventListener("touch", touchScreen) end scene:addEventListener( "show" ) function scene:hide(event) local sceneGroup = self.view local phase = event.phase Runtime:removeEventListener("touch", touchScreen) end function scene:destroy(event) end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene
config.lua :
application = { content = { width = 320, height = 480, scale = "zoomStretch", }, }