Phaser API Documentation

  Version: 
Filter

A Camera Shake effect.

This effect will shake the camera viewport by a random amount, bounded by the specified intensity, each frame.

Only the camera viewport is moved. None of the objects it is displaying are impacted, i.e. their positions do not change.

The effect will dispatch several events on the Camera itself and you can also specify an onUpdate callback, which is invoked each frame for the duration of the effect if required.

Constructor:

new Shake(camera)

Parameters:

name type description
camera Phaser.Cameras.Scene2D.Camera

The camera this effect is acting upon.

Since: 3.5.0

Members

<private> _elapsed: number
Focus
Focus

Description:

Effect elapsed timer.

Type:
number
Since: 3.5.0
Focus
Focus
<private> _offsetX: number
Focus
Focus

Description:

How much to offset the camera by horizontally.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
<private> _offsetY: number
Focus
Focus

Description:

How much to offset the camera by vertically.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
<private, nullable> _onUpdate: Phaser.Types.Cameras.Scene2D.CameraShakeCallback
Focus
Focus

Description:

This callback is invoked every frame for the duration of the effect.

Type:
Default: null
Since: 3.5.0
Focus
Focus
<private> _onUpdateScope: any
Focus
Focus

Description:

On Complete callback scope.

Type:
any
Since: 3.5.0
Focus
Focus
<readonly> camera: Phaser.Cameras.Scene2D.Camera
Focus
Focus

Description:

The Camera this effect belongs to.

Type:
Since: 3.5.0
Focus
Focus
<readonly> duration: number
Focus
Focus

Description:

The duration of the effect, in milliseconds.

Type:
number
Default: 0
Since: 3.5.0
Focus
Focus
intensity: Phaser.Math.Vector2
Focus
Focus

Description:

The intensity of the effect. Use small float values. The default when the effect starts is 0.05. This is a Vector2 object, allowing you to control the shake intensity independently across x and y. You can modify this value while the effect is active to create more varied shake effects.

Type:
Since: 3.5.0
Focus
Focus
<readonly> isRunning: boolean
Focus
Focus

Description:

Is this effect actively running?

Type:
boolean
Default: false
Since: 3.5.0
Focus
Focus
progress: number
Focus
Focus

Description:

If this effect is running this holds the current percentage of the progress, a value between 0 and 1.

Type:
number
Since: 3.5.0
Focus
Focus

Methods

destroy()
Focus
Focus

Description:

Destroys this effect, releasing it from the Camera.

Since: 3.5.0
Focus
Focus
effectComplete()
Focus
Focus

Description:

Called internally when the effect completes.

Since: 3.5.0
Focus
Focus
preRender()
Focus
Focus

Description:

The pre-render step for this effect. Called automatically by the Camera.

Since: 3.5.0
Focus
Focus
reset()
Focus
Focus

Description:

Resets this camera effect. If it was previously running, it stops instantly without calling its onComplete callback or emitting an event.

Since: 3.5.0
Focus
Focus
start([duration], [intensity], [force], [callback], [context])
Focus
Focus

Description:

Shakes the Camera by the given intensity over the duration specified.

Parameters:

name type arguments Default description
duration number <optional> 100

The duration of the effect in milliseconds.

intensity number | Phaser.Math.Vector2 <optional> 0.05

The intensity of the shake.

force boolean <optional> false

Force the shake effect to start immediately, even if already running.

callback Phaser.Types.Cameras.Scene2D.CameraShakeCallback <optional>

This callback will be invoked every frame for the duration of the effect. It is sent two arguments: A reference to the camera and a progress amount between 0 and 1 indicating how complete the effect is.

context any <optional>

The context in which the callback is invoked. Defaults to the Scene to which the Camera belongs.

Returns:
Description:

The Camera on which the effect was started.

Since: 3.5.0
Focus
Focus
update(time, delta)
Focus
Focus

Description:

The main update loop for this effect. Called automatically by the Camera.

Parameters:

name type description
time number

The current timestamp as generated by the Request Animation Frame or SetTimeout.

delta number

The delta time, in ms, elapsed since the last frame.

Since: 3.5.0
Focus
Focus