Class: FixedKeyControl

Phaser.Cameras.Controls. FixedKeyControl

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.


new FixedKeyControl(config)

Parameters:
Name Type Description
config Phaser.Types.Cameras.Controls.FixedKeyControlConfig

The Fixed Key Control configuration object.

Since: 3.0.0
Source: src/cameras/controls/FixedKeyControl.js (Line 10)

Members


active :boolean

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

Type:
  • boolean
Since: 3.0.0
Source: src/cameras/controls/FixedKeyControl.js (Line 166)

<nullable> camera :Phaser.Cameras.Scene2D.Camera

The Camera that this Control will update.

Type:
Since: 3.0.0
Default Value:
  • null
Source: src/cameras/controls/FixedKeyControl.js (Line 42)

<nullable> down :Phaser.Input.Keyboard.Key

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

Type:
Since: 3.0.0
Default Value:
  • null
Source: src/cameras/controls/FixedKeyControl.js (Line 82)

<nullable> left :Phaser.Input.Keyboard.Key

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

Type:
Since: 3.0.0
Default Value:
  • null
Source: src/cameras/controls/FixedKeyControl.js (Line 52)

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

Type:
Since: 3.0.0
Default Value:
  • null
Source: src/cameras/controls/FixedKeyControl.js (Line 62)

speedX :number

The horizontal speed the camera will move.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/cameras/controls/FixedKeyControl.js (Line 122)

speedY :number

The vertical speed the camera will move.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/cameras/controls/FixedKeyControl.js (Line 132)

<nullable> up :Phaser.Input.Keyboard.Key

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

Type:
Since: 3.0.0
Default Value:
  • null
Source: src/cameras/controls/FixedKeyControl.js (Line 72)

<nullable> zoomIn :Phaser.Input.Keyboard.Key

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

Type:
Since: 3.0.0
Default Value:
  • null
Source: src/cameras/controls/FixedKeyControl.js (Line 92)

<nullable> zoomOut :Phaser.Input.Keyboard.Key

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

Type:
Since: 3.0.0
Default Value:
  • null
Source: src/cameras/controls/FixedKeyControl.js (Line 102)

zoomSpeed :number

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

Type:
  • number
Since: 3.0.0
Default Value:
  • 0.01
Source: src/cameras/controls/FixedKeyControl.js (Line 112)

Methods


destroy()

Destroys this Key Control.

Since: 3.0.0
Source: src/cameras/controls/FixedKeyControl.js (Line 279)

setCamera(camera)

Binds this Key Control to a camera.

Parameters:
Name Type Description
camera Phaser.Cameras.Scene2D.Camera

The camera to bind this Key Control to.

Since: 3.0.0
Source: src/cameras/controls/FixedKeyControl.js (Line 206)
Returns:

This Key Control instance.

Type
Phaser.Cameras.Controls.FixedKeyControl

start()

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

Since: 3.0.0
Source: src/cameras/controls/FixedKeyControl.js (Line 176)
Returns:

This Key Control instance.

Type
Phaser.Cameras.Controls.FixedKeyControl

stop()

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

Since: 3.0.0
Source: src/cameras/controls/FixedKeyControl.js (Line 191)
Returns:

This Key Control instance.

Type
Phaser.Cameras.Controls.FixedKeyControl

update(delta)

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
Source: src/cameras/controls/FixedKeyControl.js (Line 223)