Home Reference Source
import {Camera} from 'shapez.io/js/game/camera.js'
public class | source

Camera

Extends:

BasicSerializableObject → Camera

Static Method Summary

Static Public Methods
public static
public static

getSchema(): {"zoomLevel": *, "center": *}

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public

Method Summary

Public Methods
public

addScreenShake(amount: *)

public

Binds the arrow keys

public

Returns if we can further zoom in

public

Returns if we can further zoom out

public

Cancels all interactions, that is user interaction and non user interaction

public
public

Checks if the mouse event is too close after a touch event and thus should get ignored

public

Clamps the camera zoom level within the allowed range

public

Cleans up all event listeners

public

Clears all animations

public

Internal touch move handler

public

Internal touch start handler

public

Internal touch stop handler

public

deserialize(data: *): *

public

Finds a good initial zoom level

public
public

Returns effective world space viewport bottom

public

Returns effective viewport height

public

Returns effective world space viewport left

public

Returns effective world space viewport right

public

Returns effective world space viewport top

public

Returns effective viewport width

public

Returns the visible world space rect

public

Attaches all event listeners

public

Updates the non user interaction centering

public

Updates the keyboard forces

public

Internal screen panning handler

public

Internal pan handler

public

Internal shake handler

public

Updates the non user interaction zooming

public

Returns if the user is currently interacting with the camera

public

Returns if this camera is currently moving by a non-user interaction

public

Returns if a point is on screen

public

onMouseDown(event: MouseEvent): boolean

Mousedown handler

public

onMouseMove(event: MouseEvent): boolean

Mousemove handler

public

onMouseUp(event: MouseEvent=): boolean

Mouseup handler

public

onMouseWheel(event: WheelEvent): boolean

Mousewheel event

public

onTouchEnd(event: TouchEvent=): boolean

Touch end and cancel handler

public

onTouchMove(event: TouchEvent): boolean

Touch move handler

public

onTouchStart(event: TouchEvent): boolean

Touch start handler

public

Converts from screen to world space

public

Sets a point in world space to focus on

public

Sets a desired zoom level

public

setPan(pan: Vector)

Sets the camera pan, every frame the camera will move by this amount

public

transform(context: CanvasRenderingContext2D)

Prepares a context to transform it

public

update(dt: number)

Updates the camera

public

Returns if in the next frame the viewport will change

public

Converts from world to screen space

Inherited Summary

From class BasicSerializableObject
public static
public static

getId()

public static

Should return the serialization schema

public static

verify(data: *): string | void

public

deserialize(data: any, root: import("./savegame_serializer").GameRoot): string | void

public

Static Public Methods

public static getId(): string source

Override:

BasicSerializableObject#getId

Return:

string

public static getSchema(): {"zoomLevel": *, "center": *} source

Should return the serialization schema

Override:

BasicSerializableObject#getSchema

Return:

{"zoomLevel": *, "center": *}

Public Constructors

public constructor() source

Fixes typeof DerivedComponent is not assignable to typeof Component, compiled out in non-dev builds

Override:

BasicSerializableObject#constructor

Public Members

public cameraUpdateTimeBucket: number source

public center: Vector source

public currentPan: Vector source

public currentShake: Vector source

public currentlyMoving: boolean source

public currentlyPinching: boolean source

public desiredCenter: Vector source

public desiredPan: Vector source

public desiredZoom: number source

public didMoveSinceTouchStart: boolean source

public downPreHandler: * source

public eventListenerMouseDown: * source

public eventListenerMouseMove: * source

public eventListenerMouseUp: * source

public eventListenerMousewheel: * source

public eventListenerTouchEnd: * source

public eventListenerTouchMove: * source

public eventListenerTouchStart: * source

public keyboardForce: * source

public lastMovingPosition: * source

public lastMovingPositionLastTick: * source

public lastPinchPositions: * source

public movePreHandler: * source

public numTicksStandingStill: * source

public root: GameRoot source

public touchPostMoveVelocity: Vector source

public upPostHandler: * source

public userInteraction: * source

public zoomLevel: * source

Public Methods

public addScreenShake(amount: *) source

Params:

NameTypeAttributeDescription
amount *

public bindKeys() source

Binds the arrow keys

public canZoomIn(): boolean source

Returns if we can further zoom in

Return:

boolean

public canZoomOut(): boolean source

Returns if we can further zoom out

Return:

boolean

public cancelAllInteractions() source

Cancels all interactions, that is user interaction and non user interaction

public centerOnMap() source

public checkPreventDoubleMouse(): boolean source

Checks if the mouse event is too close after a touch event and thus should get ignored

Return:

boolean

public clampZoomLevel() source

Clamps the camera zoom level within the allowed range

public cleanup() source

Cleans up all event listeners

public clearAnimations() source

Clears all animations

public combinedSingleTouchMoveHandler(x: number, y: number): boolean source

Internal touch move handler

Params:

NameTypeAttributeDescription
x number
y number

Return:

boolean

public combinedSingleTouchStartHandler(x: number, y: number) source

Internal touch start handler

Params:

NameTypeAttributeDescription
x number
y number

public combinedSingleTouchStopHandler(x: *, y: *) source

Internal touch stop handler

Params:

NameTypeAttributeDescription
x *
y *

public deserialize(data: *): * source

Override:

BasicSerializableObject#deserialize

Params:

NameTypeAttributeDescription
data *

Return:

*

public findInitialZoom(): * source

Finds a good initial zoom level

Return:

*

public getIsMapOverlayActive(): * source

Return:

*

public getViewportBottom(): * source

Returns effective world space viewport bottom

Return:

*

public getViewportHeight(): * source

Returns effective viewport height

Return:

*

public getViewportLeft(): * source

Returns effective world space viewport left

Return:

*

public getViewportRight(): * source

Returns effective world space viewport right

Return:

*

public getViewportTop(): * source

Returns effective world space viewport top

Return:

*

public getViewportWidth(): * source

Returns effective viewport width

Return:

*

public getVisibleRect(): Rectangle source

Returns the visible world space rect

Return:

Rectangle

public internalInitEvents() source

Attaches all event listeners

public internalUpdateCentering(now: number, dt: number) source

Updates the non user interaction centering

Params:

NameTypeAttributeDescription
now number

Time now in seconds

dt number

Delta time

public internalUpdateKeyboardForce(now: number, dt: number) source

Updates the keyboard forces

Params:

NameTypeAttributeDescription
now number
dt number

Delta time

public internalUpdateMousePanning(now: number, dt: number) source

Internal screen panning handler

Params:

NameTypeAttributeDescription
now number
dt number

public internalUpdatePanning(now: number, dt: number) source

Internal pan handler

Params:

NameTypeAttributeDescription
now number

Time now in seconds

dt number

Delta time

public internalUpdateShake(now: number, dt: number) source

Internal shake handler

Params:

NameTypeAttributeDescription
now number

Time now in seconds

dt number

Delta time

public internalUpdateZooming(now: number, dt: number) source

Updates the non user interaction zooming

Params:

NameTypeAttributeDescription
now number

Time now in seconds

dt number

Delta time

public isCurrentlyInteracting(): boolean source

Returns if the user is currently interacting with the camera

Return:

boolean

true if the user interacts

public isCurrentlyMovingToDesiredCenter(): * source

Returns if this camera is currently moving by a non-user interaction

Return:

*

public isWorldPointOnScreen(point: Vector): boolean source

Returns if a point is on screen

Params:

NameTypeAttributeDescription
point Vector

Return:

boolean

true if its on screen

public onMouseDown(event: MouseEvent): boolean source

Mousedown handler

Params:

NameTypeAttributeDescription
event MouseEvent

Return:

boolean

public onMouseMove(event: MouseEvent): boolean source

Mousemove handler

Params:

NameTypeAttributeDescription
event MouseEvent

Return:

boolean

public onMouseUp(event: MouseEvent=): boolean source

Mouseup handler

Params:

NameTypeAttributeDescription
event MouseEvent=

Return:

boolean

public onMouseWheel(event: WheelEvent): boolean source

Mousewheel event

Params:

NameTypeAttributeDescription
event WheelEvent

Return:

boolean

public onTouchEnd(event: TouchEvent=): boolean source

Touch end and cancel handler

Params:

NameTypeAttributeDescription
event TouchEvent=

Return:

boolean

public onTouchMove(event: TouchEvent): boolean source

Touch move handler

Params:

NameTypeAttributeDescription
event TouchEvent

Return:

boolean

public onTouchStart(event: TouchEvent): boolean source

Touch start handler

Params:

NameTypeAttributeDescription
event TouchEvent

Return:

boolean

public screenToWorld(screen: Vector): Vector source

Converts from screen to world space

Params:

NameTypeAttributeDescription
screen Vector

Return:

Vector

world space

public setDesiredCenter(center: Vector) source

Sets a point in world space to focus on

Params:

NameTypeAttributeDescription
center Vector

public setDesiredZoom(zoom: number) source

Sets a desired zoom level

Params:

NameTypeAttributeDescription
zoom number

public setPan(pan: Vector) source

Sets the camera pan, every frame the camera will move by this amount

Params:

NameTypeAttributeDescription
pan Vector

public transform(context: CanvasRenderingContext2D) source

Prepares a context to transform it

Params:

NameTypeAttributeDescription
context CanvasRenderingContext2D

public update(dt: number) source

Updates the camera

Params:

NameTypeAttributeDescription
dt number

Delta time in milliseconds

public viewportWillChange(): boolean source

Returns if in the next frame the viewport will change

Return:

boolean

true if it willchange

public worldToScreen(world: Vector): Vector source

Converts from world to screen space

Params:

NameTypeAttributeDescription
world Vector

Return:

Vector

screen space