Phaser API Documentation

  Version: 
Filter

A Fixed Key Camera Control.

This allows you to control the movement and zoom of a camera using the defined keys.

var camControl = new FixedKeyControl({
    camera: this.cameras.main,
    left: cursors.left,
    right: cursors.right,
    speed: float OR { x: 0, y: 0 }
});

Movement is precise and has no 'smoothing' applied to it.

You must call the update method of this controller every frame.

Constructor:

new FixedKeyControl(config)

Parameters:

name type description
config Phaser.Types.Cameras.Controls.FixedKeyControlConfig

The Fixed Key Control configuration object.

Since: 3.0.0

Members

<private> _zoom: number
Focus
Focus

Description:

Internal property to track the current zoom level.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
active: boolean
Focus
Focus

Description:

A flag controlling if the Controls will update the Camera or not.

Type:
boolean
Since: 3.0.0
Focus
Focus
<nullable> camera: Phaser.Cameras.Scene2D.Camera
Focus
Focus

Description:

The Camera that this Control will update.

Type:
Default: null
Since: 3.0.0
Focus
Focus
<nullable> down: Phaser.Input.Keyboard.Key
Focus
Focus

Description:

The Key to be pressed that will move the Camera down.

Type:
Default: null
Since: 3.0.0
Focus
Focus
<nullable> left: Phaser.Input.Keyboard.Key
Focus
Focus

Description:

The Key to be pressed that will move the Camera left.

Type:
Default: null
Since: 3.0.0
Focus
Focus
maxZoom: number
Focus
Focus

Description:

The largest zoom value the camera will reach when zoomed in.

Type:
number
Default: 1000
Since: 3.53.0
Focus
Focus
minZoom: number
Focus
Focus

Description:

The smallest zoom value the camera will reach when zoomed out.

Type:
number
Default: 0.001
Since: 3.53.0
Focus
Focus
speedX: number
Focus
Focus

Description:

The horizontal speed the camera will move.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
speedY: number
Focus
Focus

Description:

The vertical speed the camera will move.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
<nullable> up: Phaser.Input.Keyboard.Key
Focus
Focus

Description:

The Key to be pressed that will move the Camera up.

Type:
Default: null
Since: 3.0.0
Focus
Focus
<nullable> zoomIn: Phaser.Input.Keyboard.Key
Focus
Focus

Description:

The Key to be pressed that will zoom the Camera in.

Type:
Default: null
Since: 3.0.0
Focus
Focus
<nullable> zoomOut: Phaser.Input.Keyboard.Key
Focus
Focus

Description:

The Key to be pressed that will zoom the Camera out.

Type:
Default: null
Since: 3.0.0
Focus
Focus
zoomSpeed: number
Focus
Focus

Description:

The speed at which the camera will zoom if the zoomIn or zoomOut keys are pressed.

Type:
number
Default: 0.01
Since: 3.0.0
Focus
Focus

Methods

destroy()
Focus
Focus

Description:

Destroys this Key Control.

Since: 3.0.0
Focus
Focus
setCamera(camera)
Focus
Focus

Description:

Binds this Key Control to a camera.

Parameters:

name type description
camera Phaser.Cameras.Scene2D.Camera

The camera to bind this Key Control to.

Returns:
Description:

This Key Control instance.

Since: 3.0.0
Focus
Focus
start()
Focus
Focus

Description:

Starts the Key Control running, providing it has been linked to a camera.

Returns:
Description:

This Key Control instance.

Since: 3.0.0
Focus
Focus
stop()
Focus
Focus

Description:

Stops this Key Control from running. Call start to start it again.

Returns:
Description:

This Key Control instance.

Since: 3.0.0
Focus
Focus
update(delta)
Focus
Focus

Description:

Applies the results of pressing the control keys to the Camera.

You must call this every step, it is not called automatically.

Parameters:

name type description
delta number

The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate.

Since: 3.0.0
Focus
Focus