I try to repeat the same scene with a different picture I get the error message below, but when I leave blank in function scene:hide( event ) scene change but previous scene still on the screen
---------------------Error message-----------------------
C:\Users\game\FR\syllabe\AP\ap11.lua:101: attempt to perform arithmetic on field ‘x’ (a nil value)
stack traceback:
C:\Users\game\FR\syllabe\AP\ap11.lua:101: in function ‘func’
D:\a\corona\corona\platform\resources\init.lua:202: in function <D:\a\corona\corona\platform\resources\init.lua:189>
-----------------------------------------------------------------
someone can help me please !
below the code
local composer = require( “composer” )
local scene = composer.newScene()
local function gotoGame()
composer.gotoScene( “game.AP.ap11” )
end
– create()
function scene:create( event )
local sceneGroup = self.view
------------------------------background----------------------------------------
local anleekran = display.newImageRect( sceneGroup, “image4/anleekran.png”, 765, 1370 )
anleekran.x = display.contentCenterX
anleekran.y = display.contentCenterY
–anleekran.alpha=0.7
local tPrevious = system.getTimer()
-------------- Set up physics engine---------------
local physics = require( “physics” )
physics.start()
physics.setGravity( 0, 9.8 )
physics.setDrawMode( “normal” )
---------------- Declare initial variables ---------------------------
local letterboxWidth = math.abs(display.screenOriginX)
local letterboxHeight = math.abs(display.screenOriginY)
---------------- Create wall around the screen--------------------------
local wallL = display.newRect( sceneGroup, 470-letterboxWidth, display.contentCenterY, 140, display.actualContentHeight )
wallL.anchorX = 1
wallL.isVisible = false
physics.addBody( wallL, “static”, { bounce=1, friction=0.1 } )
local wallR = display.newRect( sceneGroup, 160+letterboxWidth, display.contentCenterY, 140, display.actualContentHeight )
wallR.anchorX = 0
wallR.isVisible = false
physics.addBody( wallR, “static”, { bounce=1, friction=0.1 } )
local wallT = display.newRect( sceneGroup, display.contentCenterX, 1350-letterboxHeight, display.actualContentWidth, 20 )
wallT.anchorY = 1
wallT.isVisible = false
physics.addBody( wallT, “static”, { bounce=0, friction=0 } )
local wallB = display.newRect( sceneGroup, display.contentCenterX, -350+letterboxHeight, display.actualContentWidth, 20 )
wallB.anchorY = 0
wallB.isVisible = false
physics.addBody( wallB, “static”, { bounce=0.4, friction=0.6 } )
– Create ball (character)
local jumper = display.newImageRect( sceneGroup, “image/image1/boulviolet.png”, 100, 100 )
physics.addBody( jumper, “dynamic”, { radius=1, bounce=0.3, friction=0.1 } )
jumper.x = 308 ; jumper.y = 70
jumper.alpha = 0.7
------------------------------------Create platforms-----------------------------
local bgap = display.newImageRect( sceneGroup, “image/image1/joyau6.png”, 150, 160 )
bgap.x=2000
bgap.y=820
physics.addBody( bgap, “static”, { bounce=0.3, friction=0.1 } )
bgap.collType=“gap”
local gap = display.newText(sceneGroup, “gap”, 1000, 820, native.systemFontBold, 65, 1 )
gap:setFillColor( 0, 0, 0)
local moon = display.newImage( sceneGroup, “test/soleil.png”, 22, 19 )
– Frame (runtime) listener to move objects
local function move( event )
– Move scene objects
local tDelta = event.time - tPrevious
tPrevious = event.time
local xOffset = ( 0.1tDelta )
local yOffset = ( 0.1tDelta )
local xOffset4 = ( 0.5*tDelta )
moon.x = moon.x + xOffset0.02
moon.y = moon.y + yOffset0.02
gap.x = gap.x - xOffset4 *0.4
bgap.x = gap.x - xOffset4 *0.4
– Move objects to other side of scene if they pass a horizontal position
if moon.x > 680 + moon.width/2 then
moon:translate ( -6802 , -6802)
end
if gap.x < -280 then
gap:translate( 5000, 0 )
end
-------------------
if bgap.x < -280 then
bgap:translate( 2000, 0 )
end
end
– Start runtime frame listener
Runtime:addEventListener( “enterFrame”, move )
local function onCollision( self, event )
local collideObject = event.other
if ( collideObject.collType ==“gap” ) then
gotoGame()
end
end
jumper.collision = onCollision
jumper:addEventListener( “collision” )
local function doJump( event )
if ( "began" == event.phase ) then
jumper:applyLinearImpulse( nil, 200/200, jumper.x, jumper.y )
end
return true
end
– Create an invisible touch-sensitive rectangle to handle screen touches
local touchRect = display.newRect( sceneGroup, 50, -200, 1460, 1600, 400 )
touchRect.isVisible = false
touchRect.isHitTestable = true
touchRect.anchorY = 0
touchRect:addEventListener( “touch”, doJump )
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
audio.play( DeFond, —
{ channel=1, ----channel=1 instructs the audio library to explicitly play the music on channel 1
loops=-1 } —loops=-1 tells the audio system to repeat (loop) the file indefinitely.
) -----
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)
Runtime:removeEventListener( “enterFrame”, move )
composer.removeScene( “game.FR.syllabe.AP.ap1” )
elseif ( phase == "did" ) then
-- Code here runs immediately after the scene goes entirely off screen
audio.stop( 1 )
composer.removeScene( “game.AP.ap1” )
end
end
– destroy()
function scene:destroy( event )
local sceneGroup = self.view
– Code here runs prior to the removal of scene’s view
–audio.dispose( DeFond )
–composer.removeScene( “game.AP.ap1” )
end
– Scene event function listeners
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene