API/core/Engine/

Engine

Engine.

Hierarchy: EventDispatcher

constructor 

new Engine(canvas: Canvas, hardwareRenderer: IHardwareRenderer)

Create engine.

Parameters

  • canvas

    The canvas to use for rendering

  • hardwareRenderer

    Graphics API renderer

features 

features: [] = []

instanceId ReadOnly

instanceId: number = ++EngineObject._instanceIdCounter

Engine unique id.

canvas 

get canvas(): Canvas

The canvas to use for rendering.

engine 

get engine(): Engine

Get the engine which the object belongs.

isPaused 

get isPaused(): boolean

Whether the engine is paused.

resourceManager 

get resourceManager(): ResourceManager

Get the resource manager.

sceneManager 

get sceneManager(): SceneManager

Get the scene manager.

targetFrameRate 

get targetFrameRate(): number

Set the target frame rate you want to achieve.

remarks It only takes effect when vSyncCount = 0 (ie, vertical synchronization is turned off). The larger the value, the higher the target frame rate, Number.POSITIVE_INFINIT represents the infinite target frame rate.

set targetFrameRate(number): void

time 

get time(): Time

Get the Time class.

vSyncCount 

get vSyncCount(): number

The number of vertical synchronization means the number of vertical blanking for one frame.

remarks0 means that the vertical synchronization is turned off.

set vSyncCount(number): void

addEventListener 

addEventListener(event: string, fn: Function, once: boolean): EventDispatcher

deprecatedUse `on/once` instead. Add a listener function with the specified event name.

Parameters

  • event

    Event name

  • fn

    Function

  • optionalonce

    Is it a one-time listener

Returns

this

createEntity 

createEntity(name: string): Entity

Create an entity.

Parameters

  • optionalname

    The name of the entity

Returns

Entity

destroy 

destroy(): void

Destroy engine.

dispatch 

dispatch(event: string, data: any): boolean

Dispatch the event with the specified event name.

Parameters

  • event

    Event name

  • optionaldata

    Data

Returns

- Whether the dispatching is successful

eventNames 

eventNames(): []

Returns the names of all registered events.

Returns

All event names

findFeature 

findFeature(Feature: any): EngineFeature

Parameters

  • Feature

hasEvent 

hasEvent(event: string): boolean

Determine whether there is event listening.

Parameters

  • event

    Event name

Returns

Returns whether there is a corresponding event

listenerCount 

listenerCount(event: string): number

Returns the number of listeners with the specified event name.

Parameters

  • event

    Event name

Returns

The count of listeners

off 

off(event: string, fn: Function): EventDispatcher

Remove the event listener(s) of the specified event name.

Parameters

  • event

    Event name

  • optionalfn

    Function, If is undefined, delete all corresponding event listeners.

on 

on(event: string, fn: Function): EventDispatcher

Add a listener/

Parameters

  • event

    Event name

  • fn

    Function

Returns

This

once 

once(event: string, fn: Function): EventDispatcher

Add a one-time listener.

Parameters

  • event

    Event name

  • fn

    Function

Returns

This

pause 

pause(): void

Pause the engine.

removeAllEventListeners 

removeAllEventListeners(event: string): void

Remove all event listeners.

Parameters

  • optionalevent

    Event name, delete all events if not passed

removeEventListener 

removeEventListener(event: string, fn: Function): EventDispatcher

deprecatedUse `off` instead. Remove the event listener(s) of the specified event name.

Parameters

  • event

    Event name

  • optionalfn

    Function, If is undefined, delete all corresponding event listeners.

resume 

resume(): void

Resume the engine.

run 

run(): void

Execution engine loop.

trigger 

trigger(e: Event): void

deprecatedUse `dispatch` instead.

Parameters

  • e

update 

update(): void

Update the engine loop manually. If you call engine.run(), you generally don't need to call this function.

registerFeature 

registerFeature(Feature: T): void

Parameters

  • Feature