Skip to content

@fibbojs / 2d / FRectangle

Class: FRectangle

A simple square in Fibbo.

Example

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

const scene = new FScene()

const square = new FRectangle(scene)
scene.addComponent(square)

Extends

Accessors

position

get position(): object

Setters & getters for transform properties

set position(p): void

Parameters

p

p.x: number

p.y: number

Returns

object

x

x: number

y

y: number

Inherited from

FPolygon.position

Defined in

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


rotation

get rotation(): number

set rotation(r): void

Parameters

r: number

Returns

number

Inherited from

FPolygon.rotation

Defined in

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


rotationDegree

get rotationDegree(): number

set rotationDegree(r): void

Parameters

r: number

Returns

number

Inherited from

FPolygon.rotationDegree

Defined in

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


scale

get scale(): object

set scale(s): void

Parameters

s

s.x: number

s.y: number

Returns

object

x

x: number

y

y: number

Inherited from

FPolygon.scale

Defined in

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


scaleX

get scaleX(): number

set scaleX(x): void

Parameters

x: number

Returns

number

Inherited from

FPolygon.scaleX

Defined in

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


scaleY

get scaleY(): number

set scaleY(y): void

Parameters

y: number

Returns

number

Inherited from

FPolygon.scaleY

Defined in

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


x

get x(): number

set x(x): void

Parameters

x: number

Returns

number

Inherited from

FPolygon.x

Defined in

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


y

get y(): number

set y(y): void

Parameters

y: number

Returns

number

Inherited from

FPolygon.y

Defined in

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

Constructors

new FRectangle()

new FRectangle(scene, options?): FRectangle

Parameters

scene: FScene

options?: FComponentOptions

Returns

FRectangle

Overrides

FPolygon.constructor

Defined in

2d/src/polygons/FRectangle.ts:19

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

Inherited from

FPolygon.emitCollisionWith

Defined in

core/dist/index.d.ts:116


initCollider()

initCollider(options?): void

Only init a collider for the component, without a rigid body. This is useful for static objects.

Parameters

options?: FColliderOptions

The options for the collider.

Returns

void

Example

ts
component.initCollider({
  position: { x: 0, y: 0 },
  scale: { x: 1, y: 1 },
  rotation: 0,
  shape: FShapes.SQUARE
})

Inherited from

FPolygon.initCollider

Defined in

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


initRigidBody()

initRigidBody(options?): void

Init a rigid body for the model.

Parameters

options?: FRigidBodyOptions

The options for the rigid body.

Returns

void

Example

ts
component.initRigidBody({
  position: { x: 0, y: 0 },
  scale: { x: 1, y: 1 },
  rotation: 0,
  shape: FShapes.SQUARE
})

Inherited from

FPolygon.initRigidBody

Defined in

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


initSensor()

initSensor(options?): void

Init a sensor for the component. This is useful for triggerings events when the component collides with other components.

Parameters

options?: FColliderOptions

The options for the collider.

Returns

void

Example

ts
component.initSensor({
  position: { x: 0, y: 0 },
  scale: { x: 1, y: 1 },
  rotation: { x: 0, y: 0 },
  shape: FShapes.SQUARE
})

Inherited from

FPolygon.initSensor

Defined in

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


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

FPolygon.onCollisionWith

Defined in

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


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

Returns

void

Overrides

FPolygon.onFrame

Defined in

2d/src/polygons/FRectangle.ts:23


setPosition()

setPosition(options): void

Set the position of the component.

Parameters

options

The options for the position.

options.x: number

The x position.

options.y: number

The y position.

Returns

void

Example

ts
component.setPosition({ x: 0, y: 0 })

Inherited from

FPolygon.setPosition

Defined in

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


setRotation()

setRotation(r): void

Set the rotation of the component in radians.

Parameters

r: number

The rotation in radians.

Returns

void

Example

ts
component.setRotation(Math.PI / 2)

Inherited from

FPolygon.setRotation

Defined in

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


setRotationDegree()

setRotationDegree(r): void

Set the rotation of the component in degrees.

Parameters

r: number

The rotation in degrees.

Returns

void

Example

ts
component.setRotationDegree(90)

Inherited from

FPolygon.setRotationDegree

Defined in

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


setScale()

setScale(options): void

Set the scale of the component.

Parameters

options

The options for the scale.

options.x: number

The x scale.

options.y: number

The y scale.

Returns

void

Example

ts
component.setScale({ x: 1, y: 1 })

Inherited from

FPolygon.setScale

Defined in

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

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

FPolygon.__CALLBACKS_ON_COLLISION__

Defined in

core/dist/index.d.ts:56


__ID__

__ID__: number

Unique identifier for the component. It is generated automatically.

Inherited from

FPolygon.__ID__

Defined in

core/dist/index.d.ts:51


__IS_2D__

__IS_2D__: boolean = true

Internal flags

Inherited from

FPolygon.__IS_2D__

Defined in

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


__IS_3D__

__IS_3D__: boolean

Internal flags

Inherited from

FPolygon.__IS_3D__

Defined in

core/dist/index.d.ts:45


collider?

optional collider: FCollider

RAPIER Collider

Inherited from

FPolygon.collider

Defined in

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


container

container: Container<ContainerChild>

PIXI container

Inherited from

FPolygon.container

Defined in

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


controller?

optional controller: FController

The controller attached to the component.

Inherited from

FPolygon.controller

Defined in

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


rigidBody?

optional rigidBody: FRigidBody

RAPIER RigidBody

Inherited from

FPolygon.rigidBody

Defined in

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


scene

scene: FScene

The scene which the component is in.

Inherited from

FPolygon.scene

Defined in

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


sensor?

optional sensor: FRigidBody

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

Inherited from

FPolygon.sensor

Defined in

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


transform

transform: FTransform

Transforms

Inherited from

FPolygon.transform

Defined in

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