RtsCamera beta
Class of @v12-engine/client/lite-views
export declare class RtsCameraTop-down camera that looks at a point on the ground. Scrolls with the screen edges, the arrow keys and middle mouse drag, zooms with the wheel, and looks around with Q and E for as long as they are held. The keys and the button are actions (camera.left, camera.turnLeft, camera.drag…), so the player's own where there are some.
Members
constructor
constructor(canvas: HTMLCanvasElement, terrain: Terrain, options?: RtsCameraOptions,
actions?: CameraActions | readonly ActionDef[]);Constructs a new instance of the RtsCamera class
bounds
get bounds(): CameraBounds | undefined;
set bounds(bounds: CameraBounds | undefined);Where the player may look (see RtsCameraOptions.bounds): a cinematic goes where it likes. A view outside comes inside at once. A lock has the say while there is one
chase
chase(point: Vec2, dt: number, smoothing: number): void;A share of the way to a point, for this frame: the share a thing smoothing seconds behind has to catch up in dt. What a smoothed follow does (GameClient.follow)
dispose
dispose(): void;Removes the camera's listeners
distance
distance: number;How far back the camera is from its focus, in cells
dolly
dolly(dy: number): void;Closer, or farther, by a drag of so many pixels: down brings it closer
dragging
get dragging(): boolean;Whether the map is being dragged with the middle button
drive
drive(camera: CameraState): void;Has a renderer's camera follow this one (renderer.camera): it stands and looks where view does from now on (the very arrays), and takes its lens and its planes each time the view is placed. The renderer's camera has no tilt of the horizon and no view without perspective of its own yet: view.roll and view.ortho say them
easeTo
easeTo(view: {
distance: number;
pitch: number;
fov?: number;
roll?: number;
height?: number;
}): void;Eases back to how far and how steeply the player looks, from where a cinematic left the camera; and to the lens, the roll and the height the view has (the RTS view's own where left out), looking at the ground again
edgePan
edgePan: boolean;Whether the pointer at the edge of the view scrolls it; yes by default
edgeSize
edgeSize: number;Pixels from the screen edge where the view starts to scroll
enabled
get enabled(): boolean;
set enabled(on: boolean);Whether it takes the keyboard and the mouse: arrows, turning, dragging with the middle button. Off, it stays where it is, as the map editor's does while a game is played over it. What code does to it (lookAt, a cinematic) works all the same
eye
get eye(): readonly [number, number, number];Where the camera stands: view.position
farthest
get farthest(): number;How far the player's view goes now, in cells: the game's limit, as far of it as the player wants (playerZoom)
flying
flying: boolean;Flying, as in Unity with the right button held: W, A, S and D move the view, Q and E take it down and up, Shift goes faster. The editor turns it on while the button is down
focus
readonly focus: Vec2;Point on the ground the camera looks at
fovNow
get fovNow(): number;The lens now, in radians: the RTS view's own, or a shot's
frame
frame(box: {
minX: number;
minZ: number;
maxX: number;
maxZ: number;
}): void;Looks at a part of the map, from far enough to see all of it, as Unity's F does: a box of the ground, in cells. As it looks now otherwise: as steep, turned as it is
free
free(): void;Lets go of the lock (lock): the view is held by bounds again
held
held: boolean;Held by a cinematic: the player's keys, the edges, the wheel and dragging move nothing, and the view does not swing back to the north. Whoever holds it moves it with setPose
insideEdges
insideEdges: boolean;Whether the edges of the view that are not the window's scroll it too: those of a game in a page of its own. No for an editor's, whose view is bordered by its bars and panels, which the pointer crosses on its way in and out. Either way an edge scrolls only under the pointer on the view itself (not over what floats on it: a panel, a menu) but where the view's edge is the window's, where the pointer stops and whatever is there counts
lock
lock(bounds: CameraBounds): void;Keeps the view in a part of the map, whatever the player does and whatever the code asks, till free: over a bounds for as long as it lasts. A view outside comes inside at once (panTo first for a move). A cinematic still goes where it likes; a part of no size pins the view to a point
locked
get locked(): CameraBounds | undefined;The part of the map the view is locked in, if any (lock)
look
look(dx: number, dy: number): void;Looks around by a drag of so many pixels, as Unity's right button does: across turns the view, up and down tilts it. It turns about where it looks
lookAt
lookAt(point: Vec2, move?: CameraMove): void;Moves the view so that it looks at the given point, inside the bounds: at once, or eased over seconds as panTo does (lookAt(point, { seconds: 1 })). Stops any move under way
maxDistance
get maxDistance(): number;How far the game lets the view go, in cells
minDistance
get minDistance(): number;How close the view may come, in cells
onBoundsChanged
onBoundsChanged?: (change: BoundsChanged) => void;What hears that what the view is held in changed: the client's boundsChanged
ortho
ortho: boolean;Drawn without perspective (an editor's top view, Numpad 5): what is far as big as what is near, the view as wide as the lens would show it at distance. Perspective, as a game's, when left as it is
overview
get overview(): number;How many cells farther than overviewFrom the view is now: 0 where it is not, and for a camera with none
overviewFrom
overviewFrom: number | undefined;The distance past which the view is an overview of the map (RtsCameraOptions.overviewFrom)
pan
pan(right: number, forward: number): void;Pans along the screen axes, in ground units
panning
get panning(): boolean;Whether a move is under way (panTo)
panSpeed
panSpeed: number;Ground units per second at the usual zoom
panTo
panTo(point: Vec2, seconds?: number, ease?: Ease | string): void;Moves the view over to a point, inside the bounds, in seconds, by an ease (see CameraMove). The player scrolling or dragging takes it back, as does anything else that places the view (lookAt, a cinematic taking the camera), and it ends a follow (GameClient.follow)
pitch
pitch: number;Angle between the view direction and the ground, in radians
pitchCurve
pitchCurve: ((distance: number) => number) | undefined;How steep the view is at a distance, in degrees (RtsCameraOptions.pitchCurve)
playerZoom
get playerZoom(): number;
set playerZoom(share: number);How much of the game's limit the player zooms out to, from 0 to 1: the setting zoom. All of it when left as it is; setLimits moves the limit, and this stays a share of it
pose
pose(): CinematicPose;Where the camera is now. With what a shot added (CinematicPose: the lens in degrees, the roll, the height, the point looked at) while a shot has it; the RTS pose alone otherwise, so the editor's K keys a shot as the view is
resetView
resetView(): void;Eases back to the view it started with: as steep, as far, turned as it rests. It still looks where it looks
restYaw
restYaw: number;The yaw the view rests at, in radians
rightTo
rightTo(out: Vec2): Vec2;The view's right along the ground, of length 1, into out: by how it is turned, whatever a shot looks at
rotateSpeed
rotateSpeed: number;Radians per second while Q or E is held
setLimits
setLimits(limits: CameraLimits): void;How close and how far the view may zoom from now on, in cells: what is left out stays, or moves with the other where the other passed it. A view past them eases back inside. What a cinematic does is not bound by them
setPose
setPose(pose: CinematicPose): void;Puts the camera at a pose at once: a cinematic moves it this way, a little every frame. A shot's lens, roll, height and point looked at are set with it, and what the pose leaves out of them is the RTS view's own (34°, no roll, the ground). While a cinematic holds the camera (held) it goes where it likes, off the map too; the player's camera stays over the map, inside what it is held in. Stops any move under way
shake
shake(x: number, z: number, strength: number): void;Shakes the view for something heavy that happened at a spot: strength is how hard where the camera looks at it, and it is felt less the farther off it was, and not at all from beyond two screens away. Not at all where the player said no (shakes)
shakes
shakes: boolean;Whether the view shakes for what is heavy (shake): the player's setting screenShake (RV91). Yes when left as it is
shakeScale
shakeScale: number;How hard the view shakes, as a part of what is asked (shake): the player's setting shakeStrength. All of it when left as it is
springBack
springBack: boolean;Whether the view turns back to its usual heading once let go of, as a game's does. An editor's stays where it is left, as in Unity
stopPan
stopPan(): void;Stops a move where it has got to (panTo)
tilt
tilt(radians: number): void;Tilts the view by radians: up towards the horizon when less than 0, down towards the ground when more
topDown
topDown(on?: boolean): void;Looks straight down at the ground, or (false) back at the slant it usually has
turns
turns: boolean;Whether the player may turn the view
update
update(dt: number): void;Moves the camera one frame: keys, edge scrolling, drags, easing toward its targets and shake, with dt the seconds since the last frame
view
readonly view: ViewCamera;The camera the view is drawn with, placed every frame: where it stands, what it looks at, its lens, its far plane, the horizon's tilt and whether it is drawn without perspective
yaw
yaw: number;Rotation around the vertical axis. 0 looks north
zoomSpeed
zoomSpeed: number;How fast the wheel zooms, times the usual (RtsCameraOptions.zoomSpeed)
zoomToPointer
zoomToPointer: boolean;Whether the wheel zooms about what is under the pointer (RtsCameraOptions.zoomToPointer)