Class: FSprite
A simple sprite in Fibbo.
Example
import { FScene, FSprite } from '@fibbojs/2d'
const scene = new FScene()
const sprite = new FSprite(scene, '/my-texture.png')
Extends
Constructors
new FSprite()
new FSprite(
scene
,options
):FSprite
Parameters
• scene: FScene
• 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
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:293
emitOnLoaded()
emitOnLoaded():
void
Emit the onLoaded callbacks.
Returns
void
Inherited from
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
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: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
Defined in
core/dist/index.d.ts:243
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:216
__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: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
FComponent
.__CALLBACKS_ON_LOADED__
Defined in
core/dist/index.d.ts:211
__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:203
__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:197
__TEXTURE__
__TEXTURE__:
Texture
The texture of the sprite.
Defined in
collider
collider:
FCollider
RAPIER Collider
Inherited from
Defined in
controller?
optional
controller:FController
The controller attached to the component.
Inherited from
Defined in
rigidBody
rigidBody:
FRigidBody
RAPIER RigidBody
Inherited from
Defined in
scene
scene:
FScene
The scene which the component is in.
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