Class: Camera
camera/camera.Camera
Represents the camera in 2D world space.
The camera's position is the centre of the viewport.
Hierarchy
โณ
Camera
Constructors
constructor
โข new Camera(centre
, vw
, vh
)
Creates a Camera instance and instantiates its Viewport with a width and height at the camera's centre.
Parameters
Name | Type | Description |
---|---|---|
centre | vec2 | The centre of the camera's viewport |
vw | number | The camera's viewport width |
vh | number | The camera's viewport height |
Overrides
Defined in
src/camera/camera.ts:25
โข new Camera(centre
, viewport
)
Creates a Camera instance and sets its viewport.
Parameters
Name | Type | Description |
---|---|---|
centre | vec2 | The centre of the camera's viewport |
viewport | Viewport | The viewport to use with the camera |
Overrides
Object2D.constructor
Defined in
src/camera/camera.ts:33
Properties
lastPos
โข lastPos: vec2
Defined in
src/camera/camera.ts:16
listeners
โข Protected
listeners: Object
= {}
Index signature
โช [index: string
]: Listener
[]
Inherited from
Defined in
src/object2d.ts:32
maxZoom
โข maxZoom: number
= 10
Defined in
src/camera/camera.ts:14
minZoom
โข minZoom: number
= 0.1
Defined in
src/camera/camera.ts:13
viewport
โข viewport: Viewport
Defined in
src/camera/camera.ts:11
zoomLevel
โข Private
zoomLevel: number
= 1
Defined in
src/camera/camera.ts:12
Methods
addEventListener
โธ addEventListener(event
, listener
): boolean
Executes a function when an event is fired.
Parameters
Name | Type | Description |
---|---|---|
event | string | The event to listen for |
listener | Listener | The function to execute when the event fired |
Returns
boolean
Wether or not the listener was added
Inherited from
Defined in
src/object2d.ts:209
fireEvent
โธ fireEvent(event
, ...e
): void
Executes all listeners attached to a given event.
Parameters
Name | Type | Description |
---|---|---|
event | string | The event to fire |
...e | any | The data to pass to each event listener |
Returns
void
Inherited from
Defined in
src/object2d.ts:185
getEventListeners
โธ getEventListeners(event
): Listener
[]
Gets the listeners attached to an event.
Parameters
Name | Type |
---|---|
event | string |
Returns
Listener
[]
An array of listeners attached to the given event
Inherited from
Defined in
src/object2d.ts:198
getEvents
โธ getEvents(): string
[]
Gets the events that can be listened to on the object.
Returns
string
[]
The events the object supports
Inherited from
Defined in
src/object2d.ts:175
getPosition
โธ getPosition(): vec2
Gets the object's position.
Returns
vec2
The object's position as a vec2
Inherited from
Defined in
src/object2d.ts:82
getRotation
โธ getRotation(): number
Gets the object's rotation as a number in radians relative to y+.
Returns
number
The object's rotation
Inherited from
Defined in
src/object2d.ts:139
getZoom
โธ getZoom(): number
Gets the zoom level of the camera.
Returns
number
The zoom level of the camera
Defined in
src/camera/camera.ts:92
moveRight
โธ moveRight(dist
): void
Moves the object's position right (x+) relative to it's rotation.
Parameters
Name | Type | Description |
---|---|---|
dist | number | The distance to move right, can be + or - |
Returns
void
Inherited from
Defined in
src/object2d.ts:100
moveUp
โธ moveUp(dist
): void
Moves the object's position up (y+) relative to it's rotation.
Parameters
Name | Type | Description |
---|---|---|
dist | number | The distance to move up, can be + or - |
Returns
void
Inherited from
Defined in
src/object2d.ts:114
removeEventListener
โธ removeEventListener(event
, listener
): boolean
Removes a listener from an event.
Parameters
Name | Type | Description |
---|---|---|
event | string | The event the listener is attached to |
listener | Listener | The listener to remove |
Returns
boolean
Wether or not the listener was removed
Inherited from
Defined in
src/object2d.ts:223
rotate
โธ rotate(angle
): void
Increments the object's rotation by an angle in radians.
Parameters
Name | Type | Description |
---|---|---|
angle | number | The angle to rotate by in radians |
Returns
void
Inherited from
Defined in
src/object2d.ts:148
setPosition
โธ setPosition(pos
): void
Sets the object's position.
Parameters
Name | Type | Description |
---|---|---|
pos | vec2 | The object's new position |
Returns
void
Inherited from
Defined in
src/object2d.ts:43
setPositionX
โธ setPositionX(x
): void
Sets the x component of the object's position.
Parameters
Name | Type | Description |
---|---|---|
x | number | The object's new x coordinate |
Returns
void
Inherited from
Defined in
src/object2d.ts:56
setPositionY
โธ setPositionY(y
): void
Sets the y component of the object's position.
Parameters
Name | Type | Description |
---|---|---|
y | number | The object's new y coordinate |
Returns
void
Inherited from
Defined in
src/object2d.ts:69
setRotation
โธ setRotation(angle
): void
Sets the object's rotation.
Parameters
Name | Type | Description |
---|---|---|
angle | number | The object's new rotation |
Returns
void
Inherited from
Defined in
src/object2d.ts:128
setZoom
โธ setZoom(zoom
): void
Sets the zoom level of the camera.
This will change the size of this.viewport
.
Parameters
Name | Type | Description |
---|---|---|
zoom | number | The zoom level |
Returns
void
Defined in
src/camera/camera.ts:76
setupEvents
โธ Protected
setupEvents(): void
Sets all the events that can be used in listeners
.
Listeners can be added for an event using:
this.listeners.eventName = [];
example
Setup listeners for "position" and "rotate" events.
this.listeners.position = [];
this.listeners.rotate = [];
Returns
void
Inherited from
Defined in
src/object2d.ts:165
translate
โธ translate(v
): void
Translates the object by the provided vector.
Parameters
Name | Type | Description |
---|---|---|
v | vec2 | The vector to translate by |
Returns
void
Inherited from
Defined in
src/object2d.ts:91
update
โธ update(): void
Updates the camera's viewport if the camera has changed position since the last call to update.
Returns
void
Defined in
src/camera/camera.ts:52
zoom
โธ zoom(zoom
): void
Zooms the camera by the given amount.
Parameters
Name | Type | Description |
---|---|---|
zoom | number | The amount to zoom by |
Returns
void
Defined in
src/camera/camera.ts:64