Hi,
I have a game which is close to being completed, but I have run into a strange purge related problem. I am following this tutorialand doing everything as it tells me.
When I run the game, everything works fine, but the only problem comes with mouse AI. If you see the video here, you will find that the mice are behaving properly. They have “dynamic” physics, they move and when they touch a static marker (invisible) I just change the xScale to -1 and reverse the speed.
So, when the level ends, I go to restart screen and click on restart.
This time when they touch the marker, they do not change the scale or speed (I debugged the code and in the code, the mice do change the speed and scale, but it does not show that it did the change. It keeps colliding with the marker repeatedly.
now when the game ends and I restart once again, the mice start to behave as they should. Can anyone tell me what is the problem here? I also remove all event listeners when the scene exits.
– CODE –
restart.lua
– Purges the prior scene
function scene:enterScene(event) local prior\_scene = storyboard.getPrevious() storyboard.purgeScene( prior\_scene ) retryButton:addEventListener ("touch", pressRetry) levelsButton:addEventListener ("touch", pressLevels) nextButton:addEventListener ("touch", pressNext) end
level.lua
– DIDEXIT SCENE –
function scene:didExitScene( event ) storyboard.purgeScene( "level" ) end
– EXIT SCENE –
function scene:exitScene(event) Runtime:removeEventListener("enterFrame", owl) Runtime:removeEventListener("touch", TouchScreen) for i = 1, #gameObject do --print(gameObject[i].x) if (gameObject[i] ~= nil) then if gameObject[i].Name == "mouse" or gameObject[i].Name == "cloud" then print(gameObject[i].Name) Runtime:removeEventListener("enterFrame", gameObject[i]) end end end end
– ON COLLISION –
local function onPostCollision( event ) if ( event.object1.Name == "mouse" and event.object2.Name == "marker" ) then event.object1.speed = 0 - event.object1.speed event.object1.xScale = event.object1.xScale \* -1 end end