Need Help Solving Bugs

Okay so i have a problem, when i press my button in the simulator it changes scenes alright i see the images, but then when i try to move the player around everything resets and then there is a copy of the image behind the actual image which is really weird. Attached u will find the screenshot of the issue, and here is my code.

display.setStatusBar(display.HiddenStatusBar) local physics = require "physics" physics.start() physics.setGravity(0,0) local storyboard = require "storyboard" local scene = storyboard.newScene() storyboard.purgeOnSceneChange = true function scene:createScene( event ) local group = self.view local background = display.newImage("Background.jpg") local player = display.newImage("Player.png") player.x = 240 player.y = 150 physics.addBody(player, "static") local enemy1 = display.newImage("Enemy.png") enemy1.x = 75 enemy1.y = 75 physics.addBody(enemy1, "static") local enemy2 = display.newImage("Enemy.png") enemy2.x = 420 enemy2.y = 290 physics.addBody(enemy2, "static") self.view:insert(background) self.view:insert(player) self.view:insert(enemy1) self.view:insert(enemy2) end function scene:enterScene( event ) local background = display.newImage("Background.jpg") local player = display.newImage("Player.png") player.x = 240 player.y = 150 physics.addBody(player, "static") local enemy1 = display.newImage("Enemy.png") enemy1.x = 75 enemy1.y = 75 physics.addBody(enemy1, "static") local enemy2 = display.newImage("Enemy.png") enemy2.x = 420 enemy2.y = 290 physics.addBody(enemy2, "static") self.view:insert(background) self.view:insert(player) self.view:insert(enemy1) self.view:insert(enemy2) function touchScreen(event) if event.phase == "began" then transition.to(player,{time=1000, x=event.x, y=event.y}) end end Runtime:addEventListener("touch", touchScreen) function enemy3() transition.to(enemy1, {time=1500, x=math.random(10,520), y=math.random(10,310), onComplete = enemy3}) end enemy3() function enemy() transition.to(enemy2, {time=1500, x=math.random(10,520), y=math.random(10,310), onComplete = enemy}) end enemy() function collision(event) print("COLLISION!") end Runtime:addEventListener("collision", collision) end function scene:exitScene( event ) end function scene:destroyScene( event ) print( "Called when scene is unloaded." ) end scene:addEventListener( "destroyScene" ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) return scene

Please help quickly!

Hello. Your problem is that you’re adding your display objects in createScene and in enterScene. You only need to do this in createScene. The enterScene method is where you start timers, listeners. etc. Check out the documentation here: http://docs.coronalabs.com/api/library/storyboard/index.html

Regards,

Kevin

Please help quickly!

Hello. Your problem is that you’re adding your display objects in createScene and in enterScene. You only need to do this in createScene. The enterScene method is where you start timers, listeners. etc. Check out the documentation here: http://docs.coronalabs.com/api/library/storyboard/index.html

Regards,

Kevin