Camera

Properties

  • orientation (dynamic) — A vector pointed in the direction of the camera
  • position (BGE.Math.Vector)
  • sortsByGroundDistance (boolean) — Sort whole objects by how far ahead they are across the ground (groundDistanceAhead()),
  • motionChecker (MotionChecker)
  • frameSize (BGE.Math.Vector)
  • projectionVersion (integer) — Bumped whenever something about the camera's projection - as opposed to its
  • zoom (float) — How much bigger the view is drawn, about its middle: 1 as it comes, 2 twice as big, 0.5
  • drawDistanceScale (float) — Multiplier on a 3D camera's maxDrawDistance, set from the renderer's quality
  • drawDistanceOverride (float) — Absolute draw distance from the renderer's quality settings; 0 or less means
  • planeDrawDistanceScale (float) — How far a 3D camera's ground plane reaches, as a multiple of maxDrawDistance - the
  • planeDrawDistanceOverride (float) — The largest absolute draw distance any quality level uses (0 = none). Set by the
  • worldToCamera (Array.<Array.<float>>)
  • name (string)

Constructor

new Camera(): Camera

Instance Methods

setFrameSize(width: integer, height: integer): void

Parameters

  • width (integer)
  • height (integer)

Returns

  • void

bumpProjectionVersion(): void

Force a projection change to be reported this frame. Public so a future setter can declare a change explicitly rather than relying on the dirty check to spot it.

Returns

  • void

checkProjectionChange(): void

protected

Returns

  • void

projectionChangedThisFrame(): boolean

protected

Returns

  • boolean

getEffectiveZoom(): float

The zoom the camera actually uses: zoom, kept within CAMERA_MIN_ZOOM-CAMERA_MAX_ZOOM so a zero or negative zoom can't divide by zero or mirror the view.

Returns

  • float

zoomTo( target: float, seconds?: float, easing?: BGE.Tweens.Easing, ): void

Eases zoom to target over seconds, from wherever it is now (a zoom already easing carries on from where it had got to). Runs on the camera's own clock, so it works with or without a Game, and keeps going while the game is paused. Writing zoom yourself, or stopZooming(), stops it.

Parameters

  • target (float) — kept within CAMERA_MIN_ZOOM-CAMERA_MAX_ZOOM
  • seconds (float, optional, default: 0.5) — 0 or less zooms at once
  • easing (BGE.Tweens.Easing, optional, default: "BGE.Tweens.Easing.SinusoidalEaseInOut") — the curve, applied to the zoom's logarithm so equal steps look like equal changes in size

Returns

  • void

isZooming(): boolean

Whether a zoomTo() is still easing.

Returns

  • boolean

stopZooming(): void

Stops a zoomTo() where it has got to.

Returns

  • void

advanceZoom(dt: float): void

Moves a zoomTo() on by dt seconds. Called every frame by checkMovement(); only call it yourself in tests.

Parameters

  • dt (float) — elapsed seconds (clamped to 0-0.1)

Returns

  • void

getZoomClockSeconds(): float

protected

Returns

  • float

onProjectionChange(): void

protected

Returns

  • void

setTarget(targetPos: BGE.Math.Vector): void

Points the camera at the target position Override in subclasses to implement different camera behaviors

Parameters

  • targetPos (BGE.Math.Vector)

Returns

  • void

useDefaultCameraTarget(): void

Returns

  • void

rotate( targetPos: BGE.Math.Vector, rotation: BGE.Math.Vector, ): void

Rotate the camera by the given rotation Override in subclasses to implement different camera behaviors

Parameters

  • targetPos (BGE.Math.Vector)
  • rotation (BGE.Math.Vector)

Returns

  • void

checkMovement(): void

Returns

  • void

checkProjectionAndMotion(): void

protected

Returns

  • void

onCameraMovement(): void

Returns

  • void

isMovingThisFrame(): boolean

Whether the camera's pose differs from the last frame's, ahead of this frame's render (movedLastFrame() is only up to date after it). A 2D camera's follow() moves it during the render, so that isn't seen here.

Returns

  • boolean

movedLastFrame(): boolean

Returns

  • boolean

distanceFromCameraFront(point: BGE.Math.Vector): float

Parameters

  • point (BGE.Math.Vector)

Returns

  • float

groundDistanceAhead(point: BGE.Math.Vector): float

How far ahead of the camera point is across the ground - see sortsByGroundDistance. A 2D camera has no ground, so it's distanceFromCameraFront().

Parameters

  • point (BGE.Math.Vector)

Returns

  • float

getDistanceFadeAlpha( point: BGE.Math.Vector, distanceScale?: float, ): float

How visible a point is given the draw-distance fade band, from 1 (fully visible) to 0 (at or past the draw distance). Only a 3D camera has a draw distance, so this is always 1 here.

Parameters

  • point (BGE.Math.Vector) — world position
  • distanceScale (float, optional, default: "1.0") — fade as if the draw distance were this many times as far (Drawable.fadeDistanceScale)

Returns

  • float

isPerspective(): boolean

Whether this camera projects world z with perspective (Camera3d), rather than ignoring it.

Returns

  • boolean

pixelsPerWorldUnitAt(point: BGE.Math.Vector): float

How many canvas pixels one world unit covers at point, e.g. to draw something sized in world units. 1 here: a 2D camera draws a world unit as a pixel.

Parameters

  • point (BGE.Math.Vector) — world position

Returns

  • float — 0 at or nearer than a perspective camera's near plane

supportsOcclusionCulling(): boolean

Whether occluders (see Drawable.isOccluder) can hide objects with this camera. Only a Camera3d can: occlusion culling needs every point's depth in front of the camera.

Returns

  • boolean

fadesWithDistance(): boolean

Whether objects fade out toward a draw distance with this camera. Always false for a camera with no draw distance.

Returns

  • boolean

getDistanceFadeAlphaForPoints( points: Array.<BGE.Math.Vector>, distanceScale?: float, ): float

How visible an object is given the draw-distance fade band, judged by whichever of its points is nearest. Always 1 for a camera with no draw distance.

Parameters

  • points (Array.<BGE.Math.Vector>) — the object's world-space bounding points
  • distanceScale (float, optional, default: "1.0") — see getDistanceFadeAlpha()

Returns

  • float

getDistanceFadeAlphaForSphere( sphere: BGE.Math.BoundingSphere, distanceScale?: float, ): float

getDistanceFadeAlphaForPoints() for points known only to lie in a sphere: their alpha when every point in it would get the same one, else -1.

Parameters

  • sphere (BGE.Math.BoundingSphere)
  • distanceScale (float, optional, default: "1.0") — see getDistanceFadeAlpha()

Returns

  • float

fixesDrawDistance(): boolean

Whether the draw distance stays at maxDrawDistance whatever the render quality level (a Camera3d with fog on). Always false for a camera with no draw distance.

Returns

  • boolean

farDistanceChangedThisFrame(): boolean

Whether the draw distance or its fade band changed this frame, so every object's fade (and far-clip) needs checking again. Always false for a camera with no draw distance.

Returns

  • boolean

isDrawDistanceTransitioning(): boolean

Whether the draw distance is still easing toward a new value. Always false for a camera with no draw distance.

Returns

  • boolean

isInView(point: BGE.Math.Vector): boolean

Parameters

  • point (BGE.Math.Vector)

Returns

  • boolean

getSphereInViewVerdict(sphere: BGE.Math.BoundingSphere): integer

isAnyInView() for points known only to lie in a sphere: 1 if it would say they're in view whatever they are, 0 if it would say they're not, -1 if it depends (the default).

Parameters

  • sphere (BGE.Math.BoundingSphere)

Returns

  • integer

isAnyInView(points: Array.<BGE.Math.Vector>): boolean

Checks whether any part of a shape, given by its world-space corner/bounding points, could be visible. The default is true when at least one point is in view.

Parameters

  • points (Array.<BGE.Math.Vector>)

Returns

  • boolean

computeWorldToCameraMatrix(): void

Returns

  • void

getDrawMode(): BGE.SceneObjectDrawMode

Returns

worldPointToCanvasPoint( pWorld: BGE.Math.Vector, ): BGE.Math.Vector

Parameters

  • pWorld (BGE.Math.Vector)

Returns

  • BGE.Math.Vector

getUpVector(): BGE.Math.Vector

A normalized vector pointing up in the camera's own view. Together with getRightVector() this spans the plane the camera is looking at, which is what a camera-facing billboard is built in. A camera that can't rotate just uses world up.

Returns

  • BGE.Math.Vector

getRightVector(): BGE.Math.Vector

A normalized vector pointing right in the camera's own view - see getUpVector().

Returns

  • BGE.Math.Vector