LittleJS 1.28.0

Camera

FollowCamera

FollowCamera - The 2D camera: follows a target and drives cameraPos, and cameraScale when it has a scale

  • Smoothing is in seconds, so it comes out the same at any frame rate
  • A dead zone lets the target move about without the view moving
  • lookAhead shows more of the way the target is going, sliding across when it turns
  • boundsMin and boundsMax keep the view over the level, centered where the level is smaller than the view; they go by the view's size without cameraAngle
  • Its pos is the middle of the view, before any cameraShake
  • The newest camera made drives the view; a game can still change cameraPos in gameUpdatePost for that frame
  • Destroy it to stop it driving the view, which stays where it was; engineObjectsDestroy removes it as it does any object, so make a new one after, or set persistent to keep it

Extends EngineObject

Constructor

new FollowCamera(target, smoothing)camera.js:83

Make a follow camera, the view goes to its target at once

target EngineObject|Vector2 optional

What to follow, an object or a position

smoothing number optional, default 0.1

Seconds it takes to close most of the gap, 0 snaps

const camera = new FollowCamera(player);
camera.lookAhead = vec2(3, 0);   // see further the way the player runs
camera.boundsMin = vec2();       // keep the view over the level
camera.boundsMax = levelSize;

Members

Methods

Inherited from EngineObject

Members

boundsMax : Vector2|undefinedcamera.js:118

Highest corner of the area the view stays in, Infinity on an axis leaves that side open

boundsMin : Vector2|undefinedcamera.js:114

Lowest corner of the area the view stays in

Size of a box in the middle of the view the target moves in without the view moving

How much more it shows the way the target goes on each axis, 0 for none

lookAheadSmoothing : numbercamera.js:111

Seconds the look takes to slide across when it turns

lookAheadTurn : numbercamera.js:109

How far the target must go back the other way before the look turns, so a jiggle does not flip it

Where the target sits from the middle of the view, the view moved by it

scale : number|undefinedcamera.js:121

The cameraScale it eases to, undefined leaves cameraScale to the game

scaleSmoothing : numbercamera.js:123

Seconds the zoom takes to close most of the gap to scale, 0 snaps

smoothing : numbercamera.js:100

Seconds it takes to close most of the gap to the target, 0 snaps

What it follows; destroyed or undefined, the view holds

Methods

activate()camera.js:136

Make this the camera that drives the view, it starts from where the view is

A camera draws nothing

Put it on the target at once, with no easing, for a level start or a teleport; the view goes there too when this camera is the one driving it

takeView()camera.js:139

Start from where the view is, called when it takes over from another camera

updateCamera()camera.js:157

Move toward the target and set the view, called by the camera plugin after the objects update

updatePhysics()camera.js:232

A camera is moved only by its target, physics leaves it alone