When pooling ordinary sprites you toggle a sprite’s active and visible properties on when the sprite is in use and off when it’s out of use (free).
With physics sprites you’ll also toggle the body.enable property on and off at the same time. It’s convenient to use the enableBody() and disableBody() methods because they can set all 3 properties at once. When recycling you should also use the reset
, x
, and y
arguments in enableBody()
to synchronize the body and game object at a new position.
If your game objects don’t have those methods, you can use
gameObject.body.enable = false;
to disable and
gameObject.body.enable = true;
gameObject.body.reset(x, y);
to enable when recycling them, in addition to toggling active
and visible
.