hi,i am running into a problem again and again when i go from one scene to another.
In my game.lua file.i have a created a button to control the player and a collision function.i am unable to remove the touch event of the button when i go to gameover.lua.
A small portion of my code looks like this:-
local composer=require("composer") local scene=composer.newScene() local centerX=display.contentWidth\*0.5; local centerY=display.contentHeight\*0.5; local physics=require("physics"); physics.start(); physics.setGravity(0,10); ------------ local right,local player,local ball; ------------ function scene:create(event) player=display.newImageRect("player.png",35,35); player.x=centerX-145; player.y=centerY-70; physics.addBody(player, "dynamic"); sceneGroup:insert(player); ball=display.newImageRect("ball.png",15,15); ball.x=100; ball.y=100; physics.addBody(ball, "dynamic"); sceneGroup:insert(ball); up=display.newImageRect("up.png",80,80); up.x=centerX+250; up.y=centerY+15; up.alpha=0.5; sceneGroup:insert(right); end local function upkey(event) if(event.phase=="began")then a1=transition.to(player,{time=100,y=player.y-150}); end end function scene:show(event) local sceneGroup=self.view local phase = event.phase if(phase=="will") then elseif(phase=="did")then up:addEventListener("touch",upkey); end end -- there is also a function for collision function scene:hide(event) right:removeEventListener("touch",rightkey); end function scene:destroy(event) transition.cancel(a1) end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) ------------------------------------------ return scene
i have another button(restart) in restart.lua at the same x and y co ordinate of upbutton so
when i go to gameover.lua on collision of player with the ball
the button restart gets triggerered on its own.
can anyone tell me how do i remove this touch event when i go from one scene to another.
also i have a problem in a Runtime event which i did not included above.
2.)when i use
Runtime:addeventListner(“enterframe”,functionname) in game.lua.
after i lose and enter gameover.lua and restart the game.
my background moves at twice its speed.
,but sometimes