Skip to main content
Version: Phaser v4.0.0

PathFollower

A PathFollower is a Sprite that automatically moves along a Phaser.Curves.Path, making it ideal for cutscenes, enemy patrol routes, moving platforms, projectile arcs, or any Game Object that should travel a predefined course through the world.

It extends Sprite, so everything available on a standard Sprite — animations, tinting, scaling, alpha, blend modes, and so on — works identically here.

A PathFollower is bound to a single Path at any one time and can traverse the full length of that Path from start to finish, in either direction, or from any given point along it to the end. Playback speed and duration are controlled via a tween-like configuration object passed to startFollow. The follower can optionally rotate to face the direction of travel, be offset from the path coordinates, or rotate independently of the Path.

Constructor

new PathFollower(scene, path, x, y, texture, [frame])

Parameters

nametypeoptionaldescription
scenePhaser.SceneNoThe Scene to which this PathFollower belongs.
pathPhaser.Curves.PathNoThe Path this PathFollower is following. It can only follow one Path at a time.
xnumberNoThe horizontal position of this Game Object in the world.
ynumberNoThe vertical position of this Game Object in the world.
texturestring | Phaser.Textures.TextureNoThe key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager.
framestring | numberYesAn optional frame from the Texture this Game Object is rendering with.

Scope: static

Extends

Phaser.GameObjects.Sprite
Phaser.GameObjects.Components.PathFollower

Source: src/gameobjects/pathfollower/PathFollower.js#L11
Since: 3.0.0

Inherited Members

From Phaser.GameObjects.Components.Alpha:

From Phaser.GameObjects.Components.BlendMode:

From Phaser.GameObjects.Components.Depth:

From Phaser.GameObjects.Components.Filters:

From Phaser.GameObjects.Components.Flip:

From Phaser.GameObjects.Components.Lighting:

From Phaser.GameObjects.Components.Mask:

From Phaser.GameObjects.Components.Origin:

From Phaser.GameObjects.Components.PathFollower:

From Phaser.GameObjects.Components.RenderNodes:

From Phaser.GameObjects.Components.ScrollFactor:

From Phaser.GameObjects.Components.Size:

From Phaser.GameObjects.Components.TextureCrop:

From Phaser.GameObjects.Components.Tint:

From Phaser.GameObjects.Components.Transform:

From Phaser.GameObjects.Components.Visible:

From Phaser.GameObjects.GameObject:

From Phaser.GameObjects.Sprite:


Public Members

pathConfig

pathConfig: Phaser.Types.GameObjects.PathFollower.PathConfig

Description:

Settings for the PathFollower.

Source: src/gameobjects/components/PathFollower.js#L93
Since: 3.0.0


pathDelta

pathDelta: Phaser.Math.Vector2

Description:

The distance the follower has traveled from the previous point to the current one, at the last update.

Source: src/gameobjects/components/PathFollower.js#L75
Since: 3.23.0


pathOffset

pathOffset: Phaser.Math.Vector2

Description:

An additional vector to add to the PathFollowers position, allowing you to offset it from the Path coordinates.

Source: src/gameobjects/components/PathFollower.js#L56
Since: 3.0.0


pathTween

pathTween: Phaser.Tweens.Tween

Description:

The Tween used for following the Path.

Source: src/gameobjects/components/PathFollower.js#L84
Since: 3.0.0


pathVector

pathVector: Phaser.Math.Vector2

Description:

A Vector2 that stores the current point of the path the follower is on.

Source: src/gameobjects/components/PathFollower.js#L66
Since: 3.0.0


Inherited Methods

From Phaser.Events.EventEmitter:

From Phaser.GameObjects.Components.Alpha:

From Phaser.GameObjects.Components.BlendMode:

From Phaser.GameObjects.Components.Depth:

From Phaser.GameObjects.Components.Filters:

From Phaser.GameObjects.Components.Flip:

From Phaser.GameObjects.Components.GetBounds:

From Phaser.GameObjects.Components.Lighting:

From Phaser.GameObjects.Components.Mask:

From Phaser.GameObjects.Components.Origin:

From Phaser.GameObjects.Components.PathFollower:

From Phaser.GameObjects.Components.RenderNodes:

From Phaser.GameObjects.Components.RenderSteps:

From Phaser.GameObjects.Components.ScrollFactor:

From Phaser.GameObjects.Components.Size:

From Phaser.GameObjects.Components.TextureCrop:

From Phaser.GameObjects.Components.Tint:

From Phaser.GameObjects.Components.Transform:

From Phaser.GameObjects.Components.Visible:

From Phaser.GameObjects.GameObject:

From Phaser.GameObjects.Sprite:


Public Methods

preUpdate

<instance> preUpdate(time, delta)

Description:

Internal update handler that advances this PathFollower along the path.

Called automatically by the Scene step, should not typically be called directly.

Access: protected

Parameters:

nametypeoptionaldescription
timenumberNoThe current timestamp as generated by the Request Animation Frame or SetTimeout.
deltanumberNoThe delta time, in ms, elapsed since the last frame.

Overrides: Phaser.GameObjects.Sprite#preUpdate

Source: src/gameobjects/pathfollower/PathFollower.js#L58
Since: 3.0.0