Collisions multiplying on every game.lua reload

Hi - Thanks for reading this. This problem is driving me crazy:

I’m having an issue with my first game. I have a game.lua file with a local collision defined that removes a life if my object hits a left, or a right border at the edge of the screen. Each hit removes a life. After 3 lives the scene transitions to gameover.lua.

The first run is fine and works as planned. After I go back to game.lua from gameover.lua, when the object hits the border, it fires TWO collisions…

The third run fires THREE collisions, and the forth fires FOUR collisions…and so on!!!

HELP!!! Do I need to kill or null out some before the scene transition?

Hi @triscocal,

Welcome to Corona. You haven’t posted your code, but most likely you are adding a collision listener every time that the scene is “shown”, so it keeps multiplying them each time. The solution is to add the collision listener just once, so when the scene is created you get one listener, and you don’t create another one at another time.

I assume you’re using the Composer scene management library?

Best regards,

Brent

Hello again,

Well, unless you are specifically destroying the scene each time you leave it, the “create” block would be the logical place to add the listener. And yes, the listener should be removed in the “destroy” block.

Anyway, check your code, see what you can resolve (if possible), and post the results when you can.

Thanks,

Brent

Fixed it! My Borders were not removing, so every time the scene reloaded, I was getting another border, so the collisions were increasing. I managed to resolve this with the following code just before I move to game over.lua:

left_border:removeSelf()

right_border:removeSelf()

Hi @triscocal,

Welcome to Corona. You haven’t posted your code, but most likely you are adding a collision listener every time that the scene is “shown”, so it keeps multiplying them each time. The solution is to add the collision listener just once, so when the scene is created you get one listener, and you don’t create another one at another time.

I assume you’re using the Composer scene management library?

Best regards,

Brent

Hello again,

Well, unless you are specifically destroying the scene each time you leave it, the “create” block would be the logical place to add the listener. And yes, the listener should be removed in the “destroy” block.

Anyway, check your code, see what you can resolve (if possible), and post the results when you can.

Thanks,

Brent

Fixed it! My Borders were not removing, so every time the scene reloaded, I was getting another border, so the collisions were increasing. I managed to resolve this with the following code just before I move to game over.lua:

left_border:removeSelf()

right_border:removeSelf()