A Smoothed Key Camera Control.
This allows you to control the movement and zoom of a camera using the defined keys. Unlike the Fixed Camera Control you can also provide physics values for acceleration, drag and maxSpeed for smoothing effects.
var controlConfig = {
camera: this.cameras.main,
left: cursors.left,
right: cursors.right,
up: cursors.up,
down: cursors.down,
zoomIn: this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Q),
zoomOut: this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.E),
zoomSpeed: 0.02,
acceleration: 0.06,
drag: 0.0005,
maxSpeed: 1.0
};
You must call the update
method of this controller every frame.
new SmoothedKeyControl(config)
name | type | description |
---|---|---|
config | Phaser.Types.Cameras.Controls.SmoothedKeyControlConfig |
The Smoothed Key Control configuration object. |
The horizontal acceleration the camera will move.
The vertical acceleration the camera will move.
A flag controlling if the Controls will update the Camera or not.
The Camera that this Control will update.
The Key to be pressed that will move the Camera down.
The horizontal drag applied to the camera when it is moving.
The vertical drag applied to the camera when it is moving.
The Key to be pressed that will move the Camera left.
The maximum horizontal speed the camera will move.
The maximum vertical speed the camera will move.
The largest zoom value the camera will reach when zoomed in.
The smallest zoom value the camera will reach when zoomed out.
The Key to be pressed that will move the Camera right.
The Key to be pressed that will move the Camera up.
The Key to be pressed that will zoom the Camera in.
The Key to be pressed that will zoom the Camera out.
The speed at which the camera will zoom if the zoomIn
or zoomOut
keys are pressed.
Destroys this Key Control.
Binds this Key Control to a camera.
name | type | description |
---|---|---|
camera | Phaser.Cameras.Scene2D.Camera |
The camera to bind this Key Control to. |
This Key Control instance.
Starts the Key Control running, providing it has been linked to a camera.
This Key Control instance.
Stops this Key Control from running. Call start
to start it again.
This Key Control instance.
Applies the results of pressing the control keys to the Camera.
You must call this every step, it is not called automatically.
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. |