Class: FSprite β
A simple sprite in Fibbo.
Example β
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 β
Overrides β
Defined in β
Methods β
__SET_POSITION__() β
__SET_POSITION__(
position
):void
Parameters β
β’ position: FVector2
Returns β
void
Inherited from β
Defined in β
__SET_ROTATION__() β
__SET_ROTATION__(
rotation
):void
Parameters β
β’ rotation: number
Returns β
void
Inherited from β
Defined in β
__SET_SCALE__() β
__SET_SCALE__(
scale
):void
Parameters β
β’ scale: FVector2
Returns β
void
Inherited from β
Defined in β
__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 β
__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 β
__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 β
Defined in β
addController() β
addController(
controller
):void
Add a controller to the component.
Parameters β
β’ controller: FController
The controller to add.
Returns β
void
Inherited from β
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 β
const player = new Player()
const enemy = new Enemy()
player.emitCollisionWith({
class: Enemy
})
const player = new Player()
const enemy = new Enemy()
player.emitCollisionWith({
object: enemy
})
Inherited from β
Defined in β
core/dist/index.d.ts:486
emitOnLoaded() β
emitOnLoaded():
void
Emit the onLoaded callbacks.
Returns β
void
Inherited from β
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 β
Defined in β
initCollider() β
initCollider(
options
?):void
Parameters β
β’ options?: FColliderOptions
Returns β
void
Inherited from β
Defined in β
initRigidBody() β
initRigidBody(
options
?):void
Parameters β
β’ options?: FRigidBodyOptions
Returns β
void
Inherited from β
Defined in β
initSensor() β
initSensor(
options
?):void
Parameters β
β’ options?: FRigidBodyOptions
Returns β
void
Inherited from β
Defined in β
loadTexture() β
loadTexture(
texture
):Promise
<void
>
Load a texture from a path.
Parameters β
β’ texture: string
The path to the texture.
Returns β
Promise
<void
>
Defined in β
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 β
const player = new Player()
const enemy = new Enemy()
player.onCollisionWith(Enemy, () => {
console.log('Player collided with an Enemy!')
})
const player = new Player()
const enemy = new Enemy()
player.onCollisionWith(enemy, () => {
console.log('Player collided with the enemy!')
})
Inherited from β
Defined in β
onFrame() β
onFrame(
callback
):void
Add a callback to be called every frame.
Parameters β
β’ callback
The callback function.
Returns β
void
Inherited from β
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 β
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 β
Defined in β
core/dist/index.d.ts:420
render() β
render(
delta
):void
Parameters β
β’ delta: number
Returns β
void
Inherited from β
Defined in β
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 β
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 β
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 β
Defined in β
__ID__ β
__ID__:
number
Unique identifier for the component. It is generated automatically.
Inherited from β
Defined in β
core/dist/index.d.ts:386
__IS_2D__ β
__IS_2D__:
boolean
=true
Internal flags
Inherited from β
Defined in β
__IS_3D__ β
__IS_3D__:
boolean
Internal flags
Inherited from β
Defined in β
core/dist/index.d.ts:380
__TEXTURE__ β
__TEXTURE__:
Texture
The texture of the sprite.
Defined in β
collider β
collider:
FCollider
RAPIER Collider
Inherited from β
Defined in β
controllers β
controllers:
FController
[]
The controllers attached to the component.
Inherited from β
Defined in β
rigidBody β
rigidBody:
FRigidBody
RAPIER RigidBody
Inherited from β
Defined in β
scene β
scene:
FScene
The scene the component is attached to.
Inherited from β
Defined in β
sensor β
sensor:
FRigidBody
Sensor (a collider that doesn't collide with other colliders, but still triggers events)
Inherited from β
Defined in β
transform β
transform:
FTransform
Transforms