Collision not Disappearing

I have this code as a platform to jump on in my game.

platform2 = display.newImage( “platform.jpg”, 1200, 1200)

physics.addBody(platform2, “static”, { friction = 0.5, bounce = 0} )

sceneGroup: insert(platform2)

When I change scene, the actual visual image of the platform disappears but the collision in still occurring. How do I get rid of this collision???

You are declaring the ‘platform2’ variable as global because you’re not using the ‘local’ keyword before it. When the scene is removed, a reference to the display object remains so it can’t be properly removed - although it will no longer show on screen. The physics body assigned to it will remain, causing problems.

Short answer: You need to declare all variables locally and clean up properly.

Also: You can add the ‘platform2’ to the sceneGroup by adding ‘sceneGroup’ as the first parameter to the ‘display.newImage()’ function call.

Note: If this doesn’t make sense.  Stop working on your game temporarily and train up on composer.*

There are guides and examples:

@horacebury,

Good catch. I missed that.

You are declaring the ‘platform2’ variable as global because you’re not using the ‘local’ keyword before it. When the scene is removed, a reference to the display object remains so it can’t be properly removed - although it will no longer show on screen. The physics body assigned to it will remain, causing problems.

Short answer: You need to declare all variables locally and clean up properly.

Also: You can add the ‘platform2’ to the sceneGroup by adding ‘sceneGroup’ as the first parameter to the ‘display.newImage()’ function call.

Note: If this doesn’t make sense.  Stop working on your game temporarily and train up on composer.*

There are guides and examples:

@horacebury,

Good catch. I missed that.