Skip to content

@fibbojs / 2d / FCamera

Class: abstract FCamera

The base class for 2D cameras in Fibbo.

Extends

  • FCamera

Extended by

Constructors

new FCamera()

new FCamera(scene, options?): FCamera

Create a new 2D camera.

Parameters

scene: FScene

The scene the camera is in.

options?: FCameraOptions

The options for the camera.

Returns

FCamera

Overrides

FCameraCore.constructor

Defined in

2d/src/cameras/FCamera.ts:36

Methods

__ON_CAMERA_ADDED_TO_SCENE_PLEASE_DO_NOT_CALL_THIS_BY_HAND__()

abstract __ON_CAMERA_ADDED_TO_SCENE_PLEASE_DO_NOT_CALL_THIS_BY_HAND__(): void

Returns

void

Defined in

2d/src/cameras/FCamera.ts:57


__SET_POSITION__()

__SET_POSITION__(position): void

Parameters

position

position.x: number

position.y: number

Returns

void

Defined in

2d/src/cameras/FCamera.ts:88


__UPDATE_POSITION__()

__UPDATE_POSITION__(): void

Update the position of the camera according to the transform. This method should be called after updating the transform properties.

Returns

void

Defined in

2d/src/cameras/FCamera.ts:67


__UPDATE_ROTATION__()

__UPDATE_ROTATION__(): void

Update the rotation of the camera according to the transform. This method should be called after updating the transform properties.

Returns

void

Defined in

2d/src/cameras/FCamera.ts:75


__UPDATE_SCALE__()

__UPDATE_SCALE__(): void

Update the scale of the camera according to the transform. This method should be called after updating the transform properties. This method does not make sense for cameras, but it is implemented for consistency.

Returns

void

Defined in

2d/src/cameras/FCamera.ts:84


emitCollisionWith()

emitCollisionWith(options): void

Emit a collision event with a given class or object.

Parameters

options

The options for the collision event.

options.class?: any

The class to emit the collision event with.

options.component?: FComponent

The component to emit the collision event with.

Returns

void

Examples

typescript
const player = new Player()
const enemy = new Enemy()
player.emitCollisionWith({
  class: Enemy
})
typescript
const player = new Player()
const enemy = new Enemy()
player.emitCollisionWith({
  object: enemy
})

Inherited from

FCameraCore.emitCollisionWith

Defined in

core/dist/index.d.ts:293


emitOnLoaded()

emitOnLoaded(): void

Emit the onLoaded callbacks.

Returns

void

Inherited from

FCameraCore.emitOnLoaded

Defined in

core/dist/index.d.ts:247


frame()

frame(delta): void

Update the component. Should be called every frame. The purpose of this method is to render the component, its mesh/sprite, and its properties.

Parameters

delta: number

The time since the last frame.

Returns

void

Inherited from

FCameraCore.frame

Defined in

core/dist/index.d.ts:233


onCollisionWith()

onCollisionWith(classOrObject, callback): () => void

Add a callback to be called when a collision occurs.

Parameters

classOrObject: any

The class or object to add the callback to.

callback

The callback to add.

Returns

Function

A function to remove the callback.

Returns

void

Examples

typescript
const player = new Player()
const enemy = new Enemy()
player.onCollisionWith(Enemy, () => {
  console.log('Player collided with an Enemy!')
})
typescript
const player = new Player()
const enemy = new Enemy()
player.onCollisionWith(enemy, () => {
  console.log('Player collided with the enemy!')
})

Inherited from

FCameraCore.onCollisionWith

Defined in

core/dist/index.d.ts:270


onFrame()

onFrame(callback): void

Add a callback to be called every frame.

Parameters

callback

The callback function.

Returns

void

Inherited from

FCameraCore.onFrame

Defined in

core/dist/index.d.ts:238


onLoaded()

onLoaded(callback): void

Add a callback to be called when the component is loaded (could be a texture, a 3D model, etc).

Parameters

callback

The callback function.

Returns

void

Inherited from

FCameraCore.onLoaded

Defined in

core/dist/index.d.ts:243


setZoom()

setZoom(zoom): void

Parameters

zoom: number

Returns

void

Defined in

2d/src/cameras/FCamera.ts:59

Properties

__CALLBACKS_ON_COLLISION__

__CALLBACKS_ON_COLLISION__: object

Callbacks for when a collision occurs with a given class or object. It is a dictionary where the key is the class name or object id and the value is an array of callbacks.

Index Signature

[key: string]: (data) => void[]

Inherited from

FCameraCore.__CALLBACKS_ON_COLLISION__

Defined in

core/dist/index.d.ts:216


__CALLBACKS_ON_FRAME__

__CALLBACKS_ON_FRAME__: () => void[]

Callbacks for when a frame is rendered.

Inherited from

FCameraCore.__CALLBACKS_ON_FRAME__

Defined in

core/dist/index.d.ts:207


__CALLBACKS_ON_LOADED__

__CALLBACKS_ON_LOADED__: () => void[]

Callbacks for when the component is loaded (could be a texture, a 3D model, etc).

Inherited from

FCameraCore.__CALLBACKS_ON_LOADED__

Defined in

core/dist/index.d.ts:211


__ID__

__ID__: number

Unique identifier for the component. It is generated automatically.

Inherited from

FCameraCore.__ID__

Defined in

core/dist/index.d.ts:203


__IS_2D__

__IS_2D__: boolean = true

Internal flags

Overrides

FCameraCore.__IS_2D__

Defined in

2d/src/cameras/FCamera.ts:17


__IS_3D__

__IS_3D__: boolean

Internal flags

Inherited from

FCameraCore.__IS_3D__

Defined in

core/dist/index.d.ts:197


controller?

optional controller: FController

The controller attached to the component.

Inherited from

FCameraCore.controller

Defined in

core/dist/index.d.ts:226


scene

scene: FScene

The scene the camera is in.

Overrides

FCameraCore.scene

Defined in

2d/src/cameras/FCamera.ts:22


transform

transform: FTransform

Transform of the camera. It is used to store the position of the camera. The scale and rotation of the transform are not used.

Defined in

2d/src/cameras/FCamera.ts:29