Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Game

An object to boot the game.

Hierarchy

  • any
    • Game

Index

Type aliases

Static OnStart

OnStart: () => void

Type declaration

    • (): void
    • Returns void

Properties

_configLoaded

_configLoaded: boolean = false

Private _engineInited

_engineInited: boolean = false

Private _frameTime

_frameTime: number

Private _gfxDevice

_gfxDevice: Device | null = null

Private _inited

_inited: boolean = false

Private _intervalId

_intervalId: number | null = null

_isCloning

_isCloning: boolean = false

Private _lastTime

_lastTime: number

_paused

_paused: boolean = true

persistRootNodes

persistRootNodes: {}

Type declaration

Private _rendererInitialized

_rendererInitialized: boolean = false

canvas

canvas: HTMLCanvasElement | null = null

The canvas of the game.

collisionMatrix

collisionMatrix: never[] = []

config

config: NormalizedGameConfig = {} as NormalizedGameConfig

The current game configuration, please be noticed any modification directly on this object after the game initialization won't take effect.

container

container: HTMLDivElement | null = null

The container of game canvas.

eventTargetOn

eventTargetOn: any = super.on

eventTargetOnce

eventTargetOnce: any = super.once

frame

frame: Record<string, unknown> | null = null

The outer frame of the game canvas; parent of game container.

groupList

groupList: any[] = []

onStart

onStart: OnStart | null = null

Callback when the scripts of engine have been load.

method

onStart

renderType

renderType: number = -1

The renderer backend of the game.

Static EVENT_ENGINE_INITED

EVENT_ENGINE_INITED: string = "engine_inited"

Event triggered after engine inited, at this point you will be able to use all engine classes.
It was defined as EVENT_RENDERER_INITED in cocos creator v1.x and renamed in v2.0. Since Cocos Creator v3.0, EVENT_RENDERER_INITED is a new event, look up define for details.

Static EVENT_GAME_INITED

EVENT_GAME_INITED: string = "game_inited"

Event triggered after game inited, at this point all engine objects and game scripts are loaded

Static EVENT_HIDE

EVENT_HIDE: string = "game_on_hide"

Event triggered when game hide to background.
Please note that this event is not 100% guaranteed to be fired on Web platform,
on native platforms, it corresponds to enter background event, os status bar or notification center may not trigger this event.

example
import { game, audioEngine } from 'cc';
game.on(Game.EVENT_HIDE, function () {
    audioEngine.pauseMusic();
    audioEngine.pauseAllEffects();
});

Static Readonly EVENT_LOW_MEMORY

EVENT_LOW_MEMORY: string = "game_on_low_memory"

Event triggered when system in low memory status.
This event is only triggered on native iOS/Android platform.

Static Readonly EVENT_RENDERER_INITED

EVENT_RENDERER_INITED: string = "renderer_inited"

Event triggered after renderer inited, at this point you will be able to use all gfx renderer feature.

Static EVENT_RESTART

EVENT_RESTART: string = "game_on_restart"

Event triggered when game restart

Static Readonly EVENT_SHOW

EVENT_SHOW: string = "game_on_show"

Event triggered when game back to foreground
Please note that this event is not 100% guaranteed to be fired on Web platform,
on native platforms, it corresponds to enter foreground event.

Static RENDER_TYPE_CANVAS

RENDER_TYPE_CANVAS: number = 0

Web Canvas 2d API as renderer backend.

Static RENDER_TYPE_OPENGL

RENDER_TYPE_OPENGL: number = 2

OpenGL API as renderer backend.

Static RENDER_TYPE_WEBGL

RENDER_TYPE_WEBGL: number = 1

WebGL API as renderer backend.

Accessors

frameTime

  • get frameTime(): number

inited

  • get inited(): boolean
  • Indicates whether the engine and the renderer has been initialized

    Returns boolean

Methods

Private ctTime

  • ctTime(id: number | undefined): void

Private determineRenderType

  • _determineRenderType(): void

Private initConfig

Private initDevice

  • _initDevice(): void

Private initEngine

  • _initEngine(): Promise<void>

Private initEvents

  • _initEvents(): void

Private runMainLoop

  • _runMainLoop(): void

Private safeEmit

  • safeEmit(event: any): void

Private setAnimFrame

  • _setAnimFrame(): void

Private setRenderPipeline

Private setRenderPipelineNShowSplash

  • _setRenderPipelineNShowSplash(): Promise<void>

Private setupRenderPipeline

  • _setupRenderPipeline(): void | Promise<void>

Private showSplashScreen

  • _showSplashScreen(): null | Promise<void>

Private stTime

  • stTime(callback: () => void): number

Private stTimeWithRAF

  • stTimeWithRAF(callback: any): number

addPersistRootNode

  • addPersistRootNode(node: Node): void
  • Add a persistent root node to the game, the persistent node won't be destroyed during scene transition.
    The target node must be placed in the root level of hierarchy, otherwise this API won't have any effect.

    Parameters

    • node: Node

      The node to be made persistent

    Returns void

end

  • end(): void

getFrameRate

  • getFrameRate(): number
  • Get frame rate set for the game, it doesn't represent the real frame rate.

    Returns number

    frame rate

init

isPaused

  • isPaused(): boolean

isPersistRootNode

  • isPersistRootNode(node: { _persistNode: any }): boolean
  • Check whether the node is a persistent root node.

    Parameters

    • node: { _persistNode: any }

      The node to be checked

      • _persistNode: any

    Returns boolean

on

  • on(type: string, callback: () => void, target?: any, once?: undefined | false | true): any
  • Register an callback of a specific event type on the game object.
    This type of event should be triggered via emit.

    Parameters

    • type: string

      A string representing the event type to listen for.

    • callback: () => void

      The callback that will be invoked when the event is dispatched.
      The callback is ignored if it is a duplicate (the callbacks are unique).

        • (): void
        • Returns void

    • Optional target: any

      The target (this object) to invoke the callback, can be null

    • Optional once: undefined | false | true

      After the first invocation, whether the callback should be unregistered.

    Returns any

    • Just returns the incoming callback so you can save the anonymous function easier.

once

  • once(type: string, callback: () => void, target?: any): any
  • Register an callback of a specific event type on the game object,
    the callback will remove itself after the first time it is triggered.

    Parameters

    • type: string

      A string representing the event type to listen for.

    • callback: () => void

      The callback that will be invoked when the event is dispatched.
      The callback is ignored if it is a duplicate (the callbacks are unique).

        • (): void
        • Returns void

    • Optional target: any

      The target (this object) to invoke the callback, can be null

    Returns any

pause

  • pause(): void
  • Pause the game main loop. This will pause:
    game logic execution, rendering process, event manager, background music and all audio effects.
    This is different with director.pause which only pause the game logic execution.

    Returns void

removePersistRootNode

  • removePersistRootNode(node: { _persistNode: boolean; uuid: string }): void
  • Remove a persistent root node.

    Parameters

    • node: { _persistNode: boolean; uuid: string }

      The node to be removed from persistent node list

      • _persistNode: boolean
      • uuid: string

    Returns void

restart

  • restart(): Promise<void>

resume

  • resume(): void
  • Resume the game from pause. This will resume:
    game logic execution, rendering process, event manager, background music and all audio effects.

    Returns void

run

  • run(onStart?: OnStart): Promise<void>
  • Run game with configuration object and onStart function.

    Parameters

    • Optional onStart: OnStart

      function to be executed after game initialized

    Returns Promise<void>

setFrameRate

  • setFrameRate(frameRate: number | string): void
  • Set frame rate of game.

    Parameters

    • frameRate: number | string

    Returns void

step

  • step(): void

Generated using TypeDoc