I am creating a game and going from the start screen into the game is no problem but when I go from restart into the game I get this error :
ERROR: Runtime error C:\Users\user\Documents\Corona Projects\app\game.lua:92: attempt to call method 'addEventListener' (a nil value)
This is my code :
player = display.newImage("player.png") player.x = 100 player.y = 300 player.myName = "player" physics.addBody(player, "static", {density=.1, bounce=0.2, friction=.2, radius=12}) function player:collision(event) if event.phase == "began" then transition.cancel() composer.gotoScene("restart", options) end end function scene:show(event) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then player:addEventListener("collision") Runtime:addEventListener("touch", onTouch) elseif ( phase == "did" ) then end end function scene:hide(event) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then display.remove( player ) display.remove( ball ) composer.removeScene( "start" ) player:removeEventListener("collision") Runtime:removeEventListener("touch", onTouch) elseif ( phase == "did" ) then print("hide removing objects") end end
This is where the error is :
player:addEventListener("collision")
I tried putting the player image in the create scene but the same thing happened . I made sure my image has the proper name . Please help .