FixedKeyControl
A Fixed Key Camera Control.
This allows you to control the movement and zoom of a camera using keyboard keys. Unlike the SmoothedKeyControl, this control applies movement and zoom changes directly each update tick with no easing or smoothing. The camera responds instantly when a key is pressed and stops instantly when it is released, making it suitable for grid-based or precision camera navigation.
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 | optional | description |
|---|---|---|---|
| config | Phaser.Types.Cameras.Controls.FixedKeyControlConfig | No | The Fixed Key Control configuration object. |
Scope: static
Source: src/cameras/controls/FixedKeyControl.js#L10
Since: 3.0.0
Public Members
active
active: boolean
Description:
A flag controlling if the Controls will update the Camera or not.
Source: src/cameras/controls/FixedKeyControl.js#L190
Since: 3.0.0
camera
camera: Phaser.Cameras.Scene2D.Camera
Description:
The Camera that this Control will update.
Source: src/cameras/controls/FixedKeyControl.js#L46
Since: 3.0.0
down
down: Phaser.Input.Keyboard.Key
Description:
The Key to be pressed that will move the Camera down.
Source: src/cameras/controls/FixedKeyControl.js#L86
Since: 3.0.0
left
left: Phaser.Input.Keyboard.Key
Description:
The Key to be pressed that will move the Camera left.
Source: src/cameras/controls/FixedKeyControl.js#L56
Since: 3.0.0
maxZoom
maxZoom: number
Description:
The largest zoom value the camera will reach when zoomed in.
Source: src/cameras/controls/FixedKeyControl.js#L136
Since: 3.53.0
minZoom
minZoom: number
Description:
The smallest zoom value the camera will reach when zoomed out.
Source: src/cameras/controls/FixedKeyControl.js#L126
Since: 3.53.0
right
right: Phaser.Input.Keyboard.Key
Description:
The Key to be pressed that will move the Camera right.
Source: src/cameras/controls/FixedKeyControl.js#L66
Since: 3.0.0
speedX
speedX: number
Description:
The horizontal speed at which the camera will scroll, in pixels per millisecond.
Source: src/cameras/controls/FixedKeyControl.js#L146
Since: 3.0.0
speedY
speedY: number
Description:
The vertical speed at which the camera will scroll, in pixels per millisecond.
Source: src/cameras/controls/FixedKeyControl.js#L156
Since: 3.0.0
up
up: Phaser.Input.Keyboard.Key
Description:
The Key to be pressed that will move the Camera up.
Source: src/cameras/controls/FixedKeyControl.js#L76
Since: 3.0.0
zoomIn
zoomIn: Phaser.Input.Keyboard.Key
Description:
The Key to be pressed that will zoom the Camera in.
Source: src/cameras/controls/FixedKeyControl.js#L96
Since: 3.0.0
zoomOut
zoomOut: Phaser.Input.Keyboard.Key
Description:
The Key to be pressed that will zoom the Camera out.
Source: src/cameras/controls/FixedKeyControl.js#L106
Since: 3.0.0
zoomSpeed
zoomSpeed: number
Description:
The amount by which the camera zoom level is changed on each update tick when the zoomIn or zoomOut keys are pressed. Unlike the scroll speed, this value is not scaled by delta time.
Source: src/cameras/controls/FixedKeyControl.js#L116
Since: 3.0.0
Public Methods
destroy
<instance> destroy()
Description:
Destroys this Key Control, nulling its camera and key references to allow for garbage collection. This Key Control cannot be used again after being destroyed.
Source: src/cameras/controls/FixedKeyControl.js#L308
Since: 3.0.0
setCamera
<instance> setCamera(camera)
Description:
Binds this Key Control to a camera.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| camera | Phaser.Cameras.Scene2D.Camera | No | The camera to bind this Key Control to. |
Returns: Phaser.Cameras.Controls.FixedKeyControl - This Key Control instance.
Source: src/cameras/controls/FixedKeyControl.js#L230
Since: 3.0.0
start
<instance> start()
Description:
Starts the Key Control running, providing it has been linked to a camera.
Returns: Phaser.Cameras.Controls.FixedKeyControl - This Key Control instance.
Source: src/cameras/controls/FixedKeyControl.js#L200
Since: 3.0.0
stop
<instance> stop()
Description:
Stops this Key Control from running. Call start to start it again.
Returns: Phaser.Cameras.Controls.FixedKeyControl - This Key Control instance.
Source: src/cameras/controls/FixedKeyControl.js#L215
Since: 3.0.0
update
<instance> update(delta)
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 | optional | description |
|---|---|---|---|
| delta | number | No | The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate. |
Source: src/cameras/controls/FixedKeyControl.js#L247
Since: 3.0.0