Skip to content

@fibbojs / 2d / FSprite

Class: FSprite ​

A simple sprite in Fibbo.

Example ​

ts
import { FScene, FSprite } from '@fibbojs/2d'

const scene = new FScene()

const sprite = new FSprite('/my-texture.png')

Extends ​

Constructors ​

new FSprite() ​

new FSprite(options): FSprite

Parameters ​

β€’ options: FSpriteOptions

Returns ​

FSprite

Overrides ​

FComponent.constructor

Defined in ​

2d/src/sprite/FSprite.ts:32

Methods ​

__SET_POSITION__() ​

__SET_POSITION__(position): void

Parameters ​

β€’ position: FVector2

Returns ​

void

Inherited from ​

FComponent.__SET_POSITION__

Defined in ​

2d/src/core/FComponent.ts:254


__SET_ROTATION__() ​

__SET_ROTATION__(rotation): void

Parameters ​

β€’ rotation: number

Returns ​

void

Inherited from ​

FComponent.__SET_ROTATION__

Defined in ​

2d/src/core/FComponent.ts:261


__SET_SCALE__() ​

__SET_SCALE__(scale): void

Parameters ​

β€’ scale: FVector2

Returns ​

void

Inherited from ​

FComponent.__SET_SCALE__

Defined in ​

2d/src/core/FComponent.ts:268


__UPDATE_POSITION__() ​

__UPDATE_POSITION__(initiator): void

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

Parameters ​

β€’ initiator: boolean = false

By default (false), the component won't be considered as the initiator of the position update. Set this to true to propagate the position update to the rigidBody, collider and sensor.

Returns ​

void

Inherited from ​

FComponent.__UPDATE_POSITION__

Defined in ​

2d/src/core/FComponent.ts:146


__UPDATE_ROTATION__() ​

__UPDATE_ROTATION__(initiator): void

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

Parameters ​

β€’ initiator: boolean = false

By default (false), the component won't be considered as the initiator of the rotation update. Set this to true to propagate the rotation update to the rigidBody, collider and sensor.

Returns ​

void

Inherited from ​

FComponent.__UPDATE_ROTATION__

Defined in ​

2d/src/core/FComponent.ts:186


__UPDATE_SCALE__() ​

__UPDATE_SCALE__(initiator): void

Update the scale of the component according to the transform. This method should be called after updating the transform properties.

Parameters ​

β€’ initiator: boolean = false

By default (false), the component won't be considered as the initiator of the scale update. Set this to true to propagate the scale update to the rigidBody, collider and sensor.

Returns ​

void

Inherited from ​

FComponent.__UPDATE_SCALE__

Defined in ​

2d/src/core/FComponent.ts:220


addController() ​

addController(controller): void

Add a controller to the component.

Parameters ​

β€’ controller: FController

The controller to add.

Returns ​

void

Inherited from ​

FComponent.addController

Defined in ​

core/dist/index.d.ts:415


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 ​

FComponent.emitCollisionWith

Defined in ​

core/dist/index.d.ts:486


emitOnLoaded() ​

emitOnLoaded(): void

Emit the onLoaded callbacks.

Returns ​

void

Inherited from ​

FComponent.emitOnLoaded

Defined in ​

core/dist/index.d.ts:440


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 ​

FComponent.frame

Defined in ​

2d/src/core/FComponent.ts:102


initCollider() ​

initCollider(options?): void

Parameters ​

β€’ options?: FColliderOptions

Returns ​

void

Inherited from ​

FComponent.initCollider

Defined in ​

2d/src/core/FComponent.ts:286


initRigidBody() ​

initRigidBody(options?): void

Parameters ​

β€’ options?: FRigidBodyOptions

Returns ​

void

Inherited from ​

FComponent.initRigidBody

Defined in ​

2d/src/core/FComponent.ts:295


initSensor() ​

initSensor(options?): void

Parameters ​

β€’ options?: FRigidBodyOptions

Returns ​

void

Inherited from ​

FComponent.initSensor

Defined in ​

2d/src/core/FComponent.ts:304


loadTexture() ​

loadTexture(texture): Promise<void>

Load a texture from a path.

Parameters ​

β€’ texture: string

The path to the texture.

Returns ​

Promise<void>

Defined in ​

2d/src/sprite/FSprite.ts:51


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 ​

FComponent.onCollisionWith

Defined in ​

2d/src/core/FComponent.ts:276


onFrame() ​

onFrame(callback): void

Add a callback to be called every frame.

Parameters ​

β€’ callback

The callback function.

Returns ​

void

Inherited from ​

FComponent.onFrame

Defined in ​

core/dist/index.d.ts:431


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 ​

FComponent.onLoaded

Defined in ​

core/dist/index.d.ts:436


removeController() ​

removeController(controller): void

Remove a controller from the component.

Parameters ​

β€’ controller: FController

The controller to remove.

Returns ​

void

Inherited from ​

FComponent.removeController

Defined in ​

core/dist/index.d.ts:420


render() ​

render(delta): void

Parameters ​

β€’ delta: number

Returns ​

void

Inherited from ​

FComponent.render

Defined in ​

2d/src/core/FComponent.ts:106


setScaleHeight() ​

setScaleHeight(height): void

Set the scale of the sprite to a specific height. The width will be calculated according to the aspect ratio of the texture.

Parameters ​

β€’ height: number

The height of the sprite.

Returns ​

void

Defined in ​

2d/src/sprite/FSprite.ts:85


setScaleWidth() ​

setScaleWidth(width): void

Set the scale of the sprite to a specific width. The height will be calculated according to the aspect ratio of the texture.

Parameters ​

β€’ width: number

The width of the sprite.

Returns ​

void

Defined in ​

2d/src/sprite/FSprite.ts:76

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 ​

FComponent.__CALLBACKS_ON_COLLISION__

Defined in ​

core/dist/index.d.ts:399


__CALLBACKS_ON_FRAME__ ​

__CALLBACKS_ON_FRAME__: () => void[]

Callbacks for when a frame is rendered.

Inherited from ​

FComponent.__CALLBACKS_ON_FRAME__

Defined in ​

core/dist/index.d.ts:390


__CALLBACKS_ON_LOADED__ ​

__CALLBACKS_ON_LOADED__: () => void[]

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

Inherited from ​

FComponent.__CALLBACKS_ON_LOADED__

Defined in ​

core/dist/index.d.ts:394


__CONTAINER__ ​

__CONTAINER__: Sprite

PIXI container

Overrides ​

FComponent.__CONTAINER__

Defined in ​

2d/src/sprite/FSprite.ts:26


__ID__ ​

__ID__: number

Unique identifier for the component. It is generated automatically.

Inherited from ​

FComponent.__ID__

Defined in ​

core/dist/index.d.ts:386


__IS_2D__ ​

__IS_2D__: boolean = true

Internal flags

Inherited from ​

FComponent.__IS_2D__

Defined in ​

2d/src/core/FComponent.ts:30


__IS_3D__ ​

__IS_3D__: boolean

Internal flags

Inherited from ​

FComponent.__IS_3D__

Defined in ​

core/dist/index.d.ts:380


__TEXTURE__ ​

__TEXTURE__: Texture

The texture of the sprite.

Defined in ​

2d/src/sprite/FSprite.ts:30


collider ​

collider: FCollider

RAPIER Collider

Inherited from ​

FComponent.collider

Defined in ​

2d/src/core/FComponent.ts:58


controllers ​

controllers: FController[]

The controllers attached to the component.

Inherited from ​

FComponent.controllers

Defined in ​

2d/src/core/FComponent.ts:38


rigidBody ​

rigidBody: FRigidBody

RAPIER RigidBody

Inherited from ​

FComponent.rigidBody

Defined in ​

2d/src/core/FComponent.ts:54


scene ​

scene: FScene

The scene the component is attached to.

Inherited from ​

FComponent.scene

Defined in ​

2d/src/core/FComponent.ts:34


sensor ​

sensor: FRigidBody

Sensor (a collider that doesn't collide with other colliders, but still triggers events)

Inherited from ​

FComponent.sensor

Defined in ​

2d/src/core/FComponent.ts:62


transform ​

transform: FTransform

Transforms

Inherited from ​

FComponent.transform

Defined in ​

2d/src/core/FComponent.ts:48