I have checked every game.lua’s columns
and I cannot find out the which handler that i did not remove.
[lua]
function playerJump (event)
if (mode == 1) and (headPlayer.y > h * 0.67) and event.phase == “began” then
headPlayer:applyForce ( 0, -20.5, headPlayer.x, headPlayer.y )
end
if (mode == 2) and (player.y > h * 0.67) and event.phase == “began” then
player:applyForce ( 0, -5.5, player.x, player.y )
end
end
–Transform Function
function playerTransform (event)
if event.phase ==“began” then
mode = 1
player.alpha = 0
physics.removeBody( player )
headPlayer.alpha = 1
physics.addBody(headPlayer, “dynamic”, { radius = 16, bounce=0, filter = headplayerCollisionFilter } )
end
if event.phase == “ended” then
mode = 2
player.alpha = 1
physics.addBody(player, “dynamic”, { radius = 16, bounce=0, filter = playerCollisionFilter } )
headPlayer.alpha = 0
end
end
function transformEnd (event)
if event.phase == “ended” then
mode = 2
player.alpha = 1
physics.addBody(player, “dynamic”, { radius = 16, bounce=0, filter = playerCollisionFilter } )
headPlayer.alpha = 0
physics.removeBody( headPlayer )
end
end
function playerOnCollisionWall ( self, event )
if event.phase == “began” then
if ( self.name == “player” and event.other.name == “wall”) then
print (“hit wall!”) --lose game
storyboard.gotoScene (“restart”)
end
if ( self.name == “headPlayer” and event.other.name == “wall”) then
print (“lose wall!”) --break the wall
end
if ( self.name == “player” and event.other.name == “pipes”) then
print (“hit pipes!”) --lose game
storyboard.gotoScene (“restart”)
end
if ( self.name == “headPlayer” and event.other.name == “pipes”) then
print (“lose pipes!”) --lose game, make sure headPlayer cant jump over pipes or too high
end
if ( self.name == “player” and event.other.name == “mouse”) then
print (“hit mouse!”) --lose game
storyboard.gotoScene (“restart”)
end
if ( self.name == “headPlayer” and event.other.name == “mouse”) then
print (“lose mouse!”) --lose game, make sure headPlayer cant jump over pipes or too high
end
end
end
function gameStart (event)
if event.phase == “began” then
if gameStarted == false then
addAllRandomTimer = timer.performWithDelay ( 1800, addRandomTimer, -1)
moveWallTimer = timer.performWithDelay ( 20, movewall, -1)
movePipesTimer = timer.performWithDelay ( 20, movePipes, -1)
moveMouseTimer = timer.performWithDelay ( 20, moveMouse, -1)
gameStarted = true
end
end
end
function addRandomTimer ()
rand = math.random (3)
if (rand < 2) then
addWallRandomTimer = timer.performWithDelay (math.random (1000,2000), addWall, 1)
else if (rand < 3) then
addPipesRandomTimer = timer.performWithDelay (math.random (1000,2000), addPipes, 1)
else if (rand < 4) then
addMouseRandomTimer = timer.performWithDelay (math.random (1000,2000), addMouse, 1)
end
end
end
end
function moveMouse ()
for a = mouseGroup.numChildren, 1, -1 do
if (mouseGroup[a].x < player.x ) then
if mouseGroup[a].scoreAdded == false then
mydata.score = mydata.score + 1
scoreText.text = mydata.score
mouseGroup[a].scoreAdded = true
end
end
if ( mouseGroup[a].x > -100 ) then
mouseGroup[a].x = mouseGroup[a].x - 6
else
mouseGroup:remove (mouseGroup[a])
mouseGroup[a] = nil
end
end
end
function movePipes ()
for a = pipeGroup.numChildren, 1, -1 do
if (pipeGroup[a].x < player.x ) then
if pipeGroup[a].scoreAdded == false then
mydata.score = mydata.score + 1
scoreText.text = mydata.score
pipeGroup[a].scoreAdded = true
end
end
if ( pipeGroup[a].x > -100 ) then
pipeGroup[a].x = pipeGroup[a].x - 6
else
pipeGroup:remove (pipeGroup[a])
pipeGroup[a] = nil
end
end
end
function movewall ()
for a = wallGroup.numChildren, 1, -1 do
if (wallGroup[a].x < player.x ) then
if wallGroup[a].scoreAdded == false then
mydata.score = mydata.score + 1
scoreText.text = mydata.score
wallGroup[a].scoreAdded = true
end
end
if ( wallGroup[a].x > -100 ) then
wallGroup[a].x = wallGroup[a].x - 6
else
wallGroup:remove (wallGroup[a])
wallGroup[a] = nil
end
end
end
function addMouse ()
mouseSheet = graphics.newImageSheet (“mouseToLeft.png”, mouseSheetInfo:getSheet() )
mouseToLeft = display.newSprite ( mouseSheet, {name = “mouseToLeft”, start = 1, count = 4, time = 175})
mouseToLeft.x = w + 100
mouseToLeft.y = h * 0.72
mouseToLeft.xScale = 0.15
mouseToLeft.yScale = 0.15
mouseToLeft.scoreAdded = false
physics.addBody (mouseToLeft, “static”, {radius = 7, density = 0.01, bounce = 0})
mouseToLeft:play ()
mouseToLeft.name = “mouse”
screenGroup:insert (mouseToLeft)
mouseGroup:insert (mouseToLeft)
screenGroup:insert(mouseGroup)
end
function addPipes ()
pipes = display.newImageRect (“pipes.png”, 30, 46)
pipes.x = w + 100
pipes.y = h * 0.7
pipes.scoreAdded = false
physics.addBody (pipes, “static”, {density = 0.01, bounce = 0})
pipes.name = “pipes”
screenGroup:insert (pipes)
pipeGroup:insert (pipes)
screenGroup:insert (pipeGroup)
end
function addWall ()
wall = display.newImageRect (“wall.png”, 15, 82)
wall.x = w + 100
wall.y = h * 0.63
wall.scoreAdded = false
wall.name = “wall”
physics.addBody (wall, “static”, { density = 0.0, bounce = 0, filter = boxCollisionfilter})
screenGroup:insert (wall)
wallGroup:insert (wall)
screenGroup:insert (wallGroup)
end
[/lua]
This is all the function i have in game.lua
[lua]function scene:enterScene( event )
storyboard.removeScene (“start”)
storyboard.removeScene (“restart”)
jump_btn:addEventListener (“touch”, playerJump)
transform_btn:addEventListener (“touch”, playerTransform)
Runtime:addEventListener (“touch”, transformEnd)
player.collision = playerOnCollisionWall
player:addEventListener (“collision”)
headPlayer.collision = playerOnCollisionWall
headPlayer:addEventListener (“collision”)
Runtime:addEventListener (“touch”, gameStart)
gameStarted = false
end[/lua]
This is the enterScene
[lua]function scene:exitScene( event )
display.remove (ground1)
display.remove (jump_btn)
display.remove (transform_btn)
Runtime:removeEventListener (“touch”, playerJump)
Runtime:removeEventListener (“touch”, playerTransform)
Runtime:removeEventListener (“touch”, transformEnd)
Runtime:removeEventListener (“touch”, gameStart)
player:removeEventListener (“collision”)
headPlayer:removeEventListener (“collision”)
timer.cancel (addAllRandomTimer)
timer.cancel (moveWallTimer)
timer.cancel (movePipesTimer)
timer.cancel (moveMouseTimer)
end[/lua]
And this is the exitScene
I have tried to remove everything that i could , but it doesn’t seem work
And i have another game having almost the same thing but it won’t cause any error