Hi Community
In my game I have function which is moving clouds - like the one in Ghost Vs. Monsters sample app. But when I switch screens with Director, I get the following error: “attempt to perform arithmetic on field ‘x’ (a nil value)”. I do remove the Runtime Enterframe listener with the “clean function - integrated in Director”, but I still get the error. I can’t get rid of that error, which is very frustrating.
Here is my code:
[lua]local clouds1
local clouds2
local Background
local drawBackground = function()
Background = display.newImageRect(“Bagground3.png”, 480, 320 )
Background.x = 240
Background.y = 160
– CLOUDS
clouds1 = display.newImageRect( “clouds-left.png”, 480, 320 )
clouds1.x = 240; clouds1.y = 160
clouds2 = display.newImageRect( “clouds-right.png”, 480, 320 )
clouds2.x = 720; clouds2.y = 160
LevelGroup:insert(Background)
LevelGroup:insert(clouds1)
LevelGroup:insert(clouds2)
end
– Main enterFrame Listener
local gameLoop = function()
if gameIsActive then
– MOVE CLOUDS SLOWLY
local cloudMoveSpeed = 0.5
clouds1.x = clouds1.x - cloudMoveSpeed
clouds2.x = clouds2.x - cloudMoveSpeed
if clouds1.x <= -240 then
clouds1.x = 1680
end
if clouds2.x <= -240 then
clouds2.x = 1680
end
end
end
local gameInit = function()
local physics = require(“physics”)
physics.start()
physics.setGravity( 0, 9.8 )
drawBackground()
–createGround()
–createLevel()
–drawHUD()
Runtime:addEventListener(“touch”, tapIt)
Runtime:addEventListener( “enterFrame”, gameLoop )
Runtime:addEventListener( “collision”, onLocalCollision )
local Checktimer = timer.performWithDelay(1000, CheckFunction, 0 )
end
unloadMe = function()
physics.stop()
stopwatch = nil
Runtime:removeEventListener( “enterFrame”, gameLoop )
Shapes[i]:removeEventListener( “touch”, dragBody )
Runtime:removeEventListener( “collision”, onLocalCollision )
Runtime:removeEventListener(“touch”, tapIt)
Check:dispose()
if Checktimer then timer.cancel( Checktimer ); end
Checktimer = nil
end
gameInit()[/lua]
Thank you for the help - it is very appreciated
[import]uid: 122802 topic_id: 26707 reply_id: 326707[/import]