Phaser API Documentation

  Version: 
enableBody(object, [bodyType])

Description:

Creates an Arcade Physics Body on a single Game Object.

If the Game Object already has a body, this method will simply add it back into the simulation.

You can specify if the body is Dynamic or Static. A dynamic body can move via velocity and acceleration. A static body remains fixed in place and as such is able to use an optimized search tree, making it ideal for static elements such as level objects. You can still collide and overlap with static bodies.

Normally, rather than calling this method directly, you'd use the helper methods available in the Arcade Physics Factory, such as:

this.physics.add.image(x, y, textureKey);
this.physics.add.sprite(x, y, textureKey);

Calling factory methods encapsulates the creation of a Game Object and the creation of its body at the same time. If you are creating custom classes then you can pass them to this method to have their bodies created.

Parameters:

name type arguments description
object Phaser.GameObjects.GameObject

The Game Object on which to create the body.

bodyType number <optional>

The type of Body to create. Either DYNAMIC_BODY or STATIC_BODY.

Returns:
Description:

The Game Object on which the body was created.

Examples:
Since: 3.0.0