Home Reference Source
import {Game} from 'terra/src/core/game.js'
public class | source

Game

Constructor Summary

Public Constructor
public

constructor(width: number, height: number, extra: Object)

The Game class takes in dimensions of the game screen

Member Summary

Public Members
public

PIXI: *

public
public
public
public
public
public
public
public
public
public
public

stage: *

public
public

Method Summary

Public Methods
public

addEntities(array: Entity[])

Create & add multiple entities

public

addEntity(entity: Entity)

Create & add a single entity

public

addEntityToStage(entity: *)

public

addSystem(system: System): System

Register a system in the game instance

public

addSystems(systems: System[])

Register multiple systems in the game instance

public

createEntities(entities: Entity[])

Create an array of entities & add them to the game

public

getComponentFromEntity(entityId: string, componentId: string): Component

Retrieves a component from a specific entity

public

getEntitiesWith(components: string[]): Entity[]

Retrieves all entities that have all provided components.

public

Retrieve an entity

public

getSystem(id: string): *

Retrive a system in the game

public

The intialization function for the game.

public

onUpdate(time: *)

The game update that happens every game frame/tick.

public

Remove entity from game

public

start()

The game start function.

public

stop()

public

update(time: *)

The game update function.

Private Methods
private

_registerSystem(system: *)

private

_rendererSetup(settings: *)

Public Constructors

public constructor(width: number, height: number, extra: Object) source

The Game class takes in dimensions of the game screen

Params:

NameTypeAttributeDescription
width number

width of game screen

height number

height of game screen

extra Object

settings for the renderer

Public Members

public PIXI: * source

public application: * source

public callbacks: Object source

public components: Object source

public entities: Object source

public hasSetup: boolean source

public height: number source

public renderer: * source

public rendererSettings: Object source

public running: boolean source

public signal: Signal source

public stage: * source

public systems: Object source

public width: number source

Public Methods

public addEntities(array: Entity[]) source

Create & add multiple entities

Params:

NameTypeAttributeDescription
array Entity[]

of entities

public addEntity(entity: Entity) source

Create & add a single entity

Params:

NameTypeAttributeDescription
entity Entity

public addEntityToStage(entity: *) source

Params:

NameTypeAttributeDescription
entity *

public addSystem(system: System): System source

Register a system in the game instance

Params:

NameTypeAttributeDescription
system System

Return:

System

public addSystems(systems: System[]) source

Register multiple systems in the game instance

Params:

NameTypeAttributeDescription
systems System[]

public createEntities(entities: Entity[]) source

Create an array of entities & add them to the game

Params:

NameTypeAttributeDescription
entities Entity[]

An array of entities

public getComponentFromEntity(entityId: string, componentId: string): Component source

Retrieves a component from a specific entity

Params:

NameTypeAttributeDescription
entityId string

The entity to retrieve the component from

componentId string

The component ID

Return:

Component

public getEntitiesWith(components: string[]): Entity[] source

Retrieves all entities that have all provided components.

Params:

NameTypeAttributeDescription
components string[]

A list of component ID's to match against

Return:

Entity[]

public getEntity(id: string): Entity source

Retrieve an entity

Params:

NameTypeAttributeDescription
id string

The ID of the entity

Return:

Entity

Returns the matching entity

public getSystem(id: string): * source

Retrive a system in the game

Params:

NameTypeAttributeDescription
id string

The ID of the system

Return:

*

public onStart() source

The intialization function for the game.

public onUpdate(time: *) source

The game update that happens every game frame/tick.

Params:

NameTypeAttributeDescription
time *

public removeEntity(ID: string) source

Remove entity from game

Params:

NameTypeAttributeDescription
ID string

of entity

public start() source

The game start function. Use onStart() callback to hook in here

public stop() source

public update(time: *) source

The game update function. Use onUpdate() callback to hook into here

Params:

NameTypeAttributeDescription
time *

Private Methods

private _registerSystem(system: *) source

Params:

NameTypeAttributeDescription
system *

private _rendererSetup(settings: *) source

Params:

NameTypeAttributeDescription
settings *