Phaser API Documentation

  Version: 
Filter
This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord
Namespace: Gravity
Phaser.Physics.Arcade.Components.Gravity

Methods

setGravity(x, [y])
Focus
Focus

Description:

Set the X and Y values of the gravitational pull to act upon this Arcade Physics Game Object. Values can be positive or negative. Larger values result in a stronger effect.

If only one value is provided, this value will be used for both the X and Y axis.

Parameters:

name type arguments Default description
x number

The gravitational force to be applied to the X-axis.

y number <optional> x

The gravitational force to be applied to the Y-axis. If this is not specified, the X value will be used.

Returns:
Description:

This Game Object.

Examples:
Since: 3.0.0
Focus
Focus
setGravityX(x)
Focus
Focus

Description:

Set the gravitational force to be applied to the X axis. Value can be positive or negative. Larger values result in a stronger effect.

Parameters:

name type description
x number

The gravitational force to be applied to the X-axis.

Returns:
Description:

This Game Object.

Examples:
Since: 3.0.0
Focus
Focus
setGravityY(y)
Focus
Focus

Description:

Set the gravitational force to be applied to the Y axis. Value can be positive or negative. Larger values result in a stronger effect.

Parameters:

name type description
y number

The gravitational force to be applied to the Y-axis.

Returns:
Description:

This Game Object.

Examples:
Since: 3.0.0
Focus
Focus