Phaser API Documentation

  Version: 
startFollow(target, [roundPixels], [lerpX], [lerpY], [offsetX], [offsetY])

Description:

Sets the Camera to follow a Game Object.

When enabled the Camera will automatically adjust its scroll position to keep the target Game Object in its center.

You can set the linear interpolation value used in the follow code. Use low lerp values (such as 0.1) to automatically smooth the camera motion.

If you find you're getting a slight "jitter" effect when following an object it's probably to do with sub-pixel rendering of the targets position. This can be rounded by setting the roundPixels argument to true to force full pixel rounding rendering. Note that this can still be broken if you have specified a non-integer zoom value on the camera. So be sure to keep the camera zoom to integers.

Parameters:

name type arguments Default description
target object | Phaser.GameObjects.GameObject

The target for the Camera to follow.

roundPixels boolean <optional> false

Round the camera position to whole integers to avoid sub-pixel rendering?

lerpX number <optional> 1

A value between 0 and 1. This value specifies the amount of linear interpolation to use when horizontally tracking the target. The closer the value to 1, the faster the camera will track.

lerpY number <optional> 1

A value between 0 and 1. This value specifies the amount of linear interpolation to use when vertically tracking the target. The closer the value to 1, the faster the camera will track.

offsetX number <optional> 0

The horizontal offset from the camera follow target.x position.

offsetY number <optional> 0

The vertical offset from the camera follow target.y position.

Returns:
Description:

This Camera instance.

Since: 3.0.0
Source: src/cameras/2d/Camera.js (Line 659)