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
| name | type | optional | description |
|---|---|---|---|
| scene | Phaser.Scene | No | The Scene to which this PathFollower belongs. |
| path | Phaser.Curves.Path | No | The Path this PathFollower is following. It can only follow one Path at a time. |
| x | number | No | The horizontal position of this Game Object in the world. |
| y | number | No | The vertical position of this Game Object in the world. |
| texture | string | Phaser.Textures.Texture | No | The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager. |
| frame | string | number | Yes | An 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:
- filterCamera
- filters
- filtersAutoFocus
- filtersFocusContext
- filtersForceComposite
- maxFilterSize
- renderFilters
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:
- active
- body
- cameraFilter
- data
- displayList
- ignoreDestroy
- input
- isDestroyed
- name
- parentContainer
- renderFlags
- scene
- state
- tabIndex
- type
- vertexRoundMode
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:
- addListener
- emit
- eventNames
- listenerCount
- listeners
- off
- on
- once
- removeAllListeners
- removeListener
- shutdown
From Phaser.GameObjects.Components.Alpha:
From Phaser.GameObjects.Components.BlendMode:
From Phaser.GameObjects.Components.Depth:
From Phaser.GameObjects.Components.Filters:
- enableFilters
- focusFilters
- focusFiltersOnCamera
- focusFiltersOverride
- renderWebGLFilters
- setFiltersAutoFocus
- setFiltersFocusContext
- setFiltersForceComposite
- setFilterSize
- setRenderFilters
- willRenderFilters
From Phaser.GameObjects.Components.Flip:
From Phaser.GameObjects.Components.GetBounds:
- getBottomCenter
- getBottomLeft
- getBottomRight
- getBounds
- getCenter
- getLeftCenter
- getRightCenter
- getTopCenter
- getTopLeft
- getTopRight
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:
- copyPosition
- getLocalPoint
- getLocalTransformMatrix
- getParentRotation
- getWorldPoint
- getWorldTransformMatrix
- setAngle
- setPosition
- setRandomPosition
- setRotation
- setScale
- setW
- setX
- setY
- setZ
From Phaser.GameObjects.Components.Visible:
From Phaser.GameObjects.GameObject:
- addToDisplayList
- addToUpdateList
- destroy
- disableInteractive
- getData
- getDisplayList
- getIndexList
- incData
- removeFromDisplayList
- removeFromUpdateList
- removeInteractive
- setActive
- setData
- setDataEnabled
- setInteractive
- setName
- setState
- setVertexRoundMode
- toggleData
- update
- willRender
- willRoundVertices
From Phaser.GameObjects.Sprite:
- addedToScene
- chain
- play
- playAfterDelay
- playAfterRepeat
- playReverse
- removedFromScene
- stop
- stopAfterDelay
- stopAfterRepeat
- stopOnFrame
- toJSON
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:
| name | type | optional | description |
|---|---|---|---|
| time | number | No | The current timestamp as generated by the Request Animation Frame or SetTimeout. |
| delta | number | No | The 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