Cocos Creator API

1.1.1

Cocos Creator is a highly customizable game development tool that utilizes the power of cocos2d-x.

Game

Module: cc

cc.game is the singleton object for game related functions.

Properties

frame Object

The outer frame of the game canvas, parent of cc.container.

container Object

The container of game canvas, equals to cc.container.

canvas Object

The canvas of the game, equals to cc._canvas.

config Object

The current game configuration, including:

  1. debugMode
    "debugMode" possible values :
    0 - No message will be printed.
    1 - cc.error, cc.assert, cc.warn, cc.log will print in console.
    2 - cc.error, cc.assert, cc.warn will print in console.
    3 - cc.error, cc.assert will print in console.
    4 - cc.error, cc.assert, cc.warn, cc.log will print on canvas, available only on web.
    5 - cc.error, cc.assert, cc.warn will print on canvas, available only on web.
    6 - cc.error, cc.assert will print on canvas, available only on web.
  2. showFPS
    Left bottom corner fps information will show when "showFPS" equals true, otherwise it will be hide.
  3. frameRate
    "frameRate" set the wanted frame rate for your game, but the real fps depends on your game implementation and the running environment.
  4. id
    "gameCanvas" sets the id of your canvas element on the web page, it's useful only on web.
  5. renderMode
    "renderMode" sets the renderer type, only useful on web :
    0 - Automatically chosen by engine
    1 - Forced to use canvas renderer
    2 - Forced to use WebGL renderer, but this will be ignored on mobile browsers
  6. scenes
    "scenes" include available scenes in the current bundle.

    Please DO NOT modify this object directly, it won't have any effect.

There are no properties that match your current filter settings. You can change your filter settings in the index section on this page. index

Methods

onStart ( )

Callback when the scripts of engine have been load.

onStop ( )

Callback when game exits.

setFrameRate
(
  • frameRate
)

Set frameRate of game.

name type description
frameRate Number

step ( )

Run the game frame by frame.

pause ( )

Pause the gameļ¼Œpause main loop.

resume ( )

Resume the game from pause.

isPaused ( ) Boolean

Check whether the game is paused.

returns:

type: Boolean

restart ( )

Restart game.

prepare
(
  • cb
)

Prepare game.

name type description
cb Function

run
(
  • [config ]
  • [onStart ]
)

Run game with configuration object and onStart function.

name type description
config optional Object | Function

Pass configuration object or onStart function

onStart optional Function

function to be executed after game initialized

addPersistRootNode
(
  • node
)

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.

name type description
node Node

The node to be made persistent

removePersistRootNode
(
  • node
)

Remove a persistent root node.

name type description
node Node

The node to be removed from persistent node list

isPersistRootNode
(
  • node
)
Boolean

Check whether the node is a persistent root node.

name type description
node Node

The node to be checked

returns:

type: Boolean

There are no methods that match your current filter settings. You can change your filter settings in the index section on this page. index