Skip to content

@fibbojs / core / FComponent

Class: abstract FComponent

The base class for all 2D and 3D components in Fibbo.

Extended by

Constructors

new FComponent()

new FComponent(): FComponent

Returns

FComponent

Defined in

core/src/FComponent.ts:46

Methods

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
})

Defined in

core/src/FComponent.ts:135


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!')
})

Defined in

core/src/FComponent.ts:85


onFrame()

onFrame(delta): void

Update the component. Should be called every frame. The purpose of onFrame on FComponent is really to render the component, its mesh/sprite and its properties. Any changes on its transform should be done on the controller, not here.

Parameters

delta: number

The time since the last frame.

Returns

void

Defined in

core/src/FComponent.ts:56

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[]

Defined in

core/src/FComponent.ts:39


__ID__

__ID__: number

Unique identifier for the component. It is generated automatically.

Defined in

core/src/FComponent.ts:33


__IS_2D__

__IS_2D__: boolean = false

Defined in

core/src/FComponent.ts:27


__IS_3D__

__IS_3D__: boolean = false

Internal flags

Defined in

core/src/FComponent.ts:26


controller?

optional controller: FController

The controller attached to the component.

Defined in

core/src/FComponent.ts:44