Arcade Sprite Pool

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. enableBody() also includes an optional reset which synchronizes the body and game object at a new position.

You can fill a physics group with inactive (free) sprites by passing

{ active: false, visible: false, enable: false }

Thank you !!

I was just looking for this, I was deactivating my sprites but the physics kept updating.
enable/disable body to the rescue =)

Here the bodies are colored with phaser-plugin-debug-body-colors. Note

  • At the start, there are disabled bodies (gray) in the top-left of the game canvas. Those are the bodies of the free (inactive) sprites. They are visible there until the last sprite is activated.
  • There are disabled bodies (gray) at the bottom border, where sprites are deactivated. They remain there until the sprite is reactivated.

1 Like