Cocos Creator API

0.7.1

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

Module Editor

Page Level Editor

Properties

assetdb AssetDB

The AssetDB instance

App Object

The Editor.App is your app.js module. Read more details in Define your application.

name String

The name of your app. It is defined in the name field in package.json

version String

your app version

path String

The current app.js running directory.

home String

Your application's data path. Usually it is ~/.{your-app-name}

extend Function

Extends Editor.App

versions Object

versions of your app and submodules

frameworkPath String

The editor framework module path. Usually it is {your-app}/editor-framework/

Methods

log
(
  • [args ]
)

Log the normal message and show on the console. The method will send ipc message console:log to all windows.

name type description
args optional ...

whatever arguments the message needs

success
(
  • [args ]
)

Log the success message and show on the console The method will send ipc message console:success to all windows.

name type description
args optional ...

whatever arguments the message needs

failed
(
  • [args ]
)

Log the failed message and show on the console The method will send ipc message console:failed to all windows.

name type description
args optional ...

whatever arguments the message needs

info
(
  • [args ]
)

Log the info message and show on the console The method will send ipc message console:info to all windows.

name type description
args optional ...

whatever arguments the message needs

warn
(
  • [args ]
)

Log the warnning message and show on the console, it also shows the call stack start from the function call it. The method will send ipc message console:warn to all windows.

name type description
args optional ...

whatever arguments the message needs

error
(
  • [args ]
)

Log the error message and show on the console, it also shows the call stack start from the function call it. The method will sends ipc message console:error to all windows.

name type description
args optional ...

whatever arguments the message needs

fatal
(
  • [args ]
)

Log the fatal message and show on the console, the app will quit immediately after that.

name type description
args optional ...

whatever arguments the message needs

connectToConsole ( )

Connect to console panel. Once the console connected, all logs will kept in core-level and display on the console panel in page-level.

clearLog ( )

Clear the logs

loadProfile
(
  • name
  • type
  • defaultProfile
)
object

Load profile via name and type, if no profile found, it will use the defaultProfile and save it to the disk. You must register your profile path with type via {@link Editor.registerProfilePath} before you can use it. The Editor Framework will search a profile under your register path with the name.

name type description
name string

The name of the profile.

type string

The type of the profile, make sure you register the type via {@link Editor.registerProfilePath}.

defaultProfile object

The default profile to use if the profile is not found.

returns:

type: object

A profile object with two additional function: - save: save the profile. - clear: clear all properties in the profile.

examples:

// register a project profile
Editor.registerProfilePath( 'project', '~/foo/bar');

// load the profile at ~/foo/bar/foobar.json
let foobarProfile = Editor.loadProfile( 'foobar', 'project', {
  foo: 'foo',
  bar: 'bar',
});

// change and save your profile
foobarProfile.foo = 'hello foo';
foobarProfile.save();

loadAllPackages ( )

Search and load all packages from the path you registerred Editor.registerPackagePath

require
(
  • url
)

Require module through url path

name type description
url string

execSpawn
(
  • command
  • options
)

Spawn child process that start from console

name type description
command string
options object

watchPackages ( )

Watch packages

registerProfilePath
(
  • type
  • path
)

Register profile type with the path you provide. Editor.loadProfile

name type description
type string

The type of the profile you want to register.

path string

The path for the register type.

registerDefaultLayout
(
  • path
)

Register a path, when loading packages, it will search the path you registerred. Editor.loadPackages

name type description
path string

A absolute path for searching your packages.

init
(
  • opts
  • profile
  • package-search-path
  • main-menu
  • panel-window
  • layout
  • selection
  • i18n
)

init editor during App.init

name type description
opts object

options

profile object

profile type to path

package-search-path array

package search path

main-menu function

a function return the new main-menu template

panel-window string

panel window url

layout string

default layout file

selection array

selection type

i18n array

i18n phrases

reset ( )

reset editor

sendToWindowsExclude
(
  • channel
  • [args ]
  • excluded
)

Send args... to windows except the excluded

name type description
channel string
args optional ...

whatever arguments the message needs

excluded object

A WebContents object.

sendToWindows
(
  • channel
  • [args ]
)

Send args... to all opened windows via channel in asynchronous message. The page-level can handle it by listening to the channel event of the ipc module.

name type description
channel string
args optional ...

whatever arguments the message needs

examples:

In core-level:

`js
Editor.sendToWindows('foo:bar', 'Hello World!');

In page-level:

// index.html


  



sendToCore
(
  • channel
  • [args ]
)

Send args... to core itself via channel in asynchronous message.

name type description
channel string
args optional ...

whatever arguments the message needs

sendToAll
(
  • channel
  • [args ]
)

Send args... to all opened window and core via channel in asynchronous message.

name type description
channel string
args optional ...

whatever arguments the message needs

sendToPanel
(
  • panelID
  • channel
  • [args ]
)

Send args... to specific panel via channel in asynchronous message.

name type description
panelID string
channel string
args optional ...

whatever arguments the message needs

examples:

Editor.sendToPanel( 'package.panel', 'ipc-foo-bar', 'arg1', 'arg2', ... );

sendToMainWindow
(
  • channel
  • [args ]
)

Send args... to main window via channel in asynchronous message.

name type description
channel string
args optional ...

whatever arguments the message needs

url
(
  • url
)

Convert a url by its protocol to a filesystem path. This function is useful when you try to get some internal file. You can use {@link Editor.registerProtocol} to register and map your filesystem path to url. By default, Editor Framework register editor-framework:// and app:// protocol.

name type description
url string

examples:

// it will return "{your-app-path}/foobar/foobar.js"
Editor.url('app://foobar/foobar.js');

registerProtocol
(
  • protocol
  • fn
)

Register a protocol so that {@link Editor.url} can use it to convert an url to the filesystem path. The fn accept an url Object via url.parse

name type description
protocol string
fn function

examples:

const Path = require('path');

let _url2path = base => {
  return urlInfo => {
    if ( urlInfo.pathname ) {
      return Path.join( base, urlInfo.host, urlInfo.pathname );
    }
    return Path.join( base, urlInfo.host );
  };
};

Editor.registerProtocol('editor-framework', _url2path(Editor.frameworkPath));

require
(
  • url
)

Require module through url path

name type description
url string

log
(
  • [arg ]
)

Log the normal message and show on the console. The method will send ipc message console:log to core.

name type description
arg optional ...

whatever arguments the message needs

sendToCoreSync
(
  • message
  • [arg ]
)
Unknown

Send message to core-level synchronized and return a result which is responded from core-level

name type description
message string

the message to send

arg optional ...

whatever arguments the message needs

returns:

results

sendToCore
(
  • message
  • [arg ]
)

Send message to editor-core, which is so called as main app, or atom shell's browser side.

name type description
message string

the message to send

arg optional ...

whatever arguments the message needs

sendToWindows
(
  • message
  • [arg ]
  • [options ]
)

Broadcast message to all pages. The page is so called as atom shell's web side. Each application window is an independent page and has its own JavaScript context.

name type description
message string

the message to send

arg optional ...

whatever arguments the message needs

options optional object

you can indicate the options such as Editor.selfExcluded

sendToMainWindow
(
  • message
  • [arg ]
)

Broadcast message to main page. The page is so called as atom shell's web side. Each application window is an independent page and has its own JavaScript context.

name type description
message string

the message to send

arg optional ...

whatever arguments the message needs

sendToAll
(
  • message
  • [arg ]
  • [options ]
)

Broadcast message to all pages and editor-core

name type description
message string

the message to send

arg optional ...

whatever arguments the message needs

options optional object

you can indicate the options such as Editor.selfExcluded

sendToPanel
(
  • panelID
  • message
  • [arg ]
)

Send message to specific panel

name type description
panelID string

the panel id

message string

the message to send

arg optional ...

whatever arguments the message needs

sendRequestToCore
(
  • channel
  • [arg ]
  • reply
)
number

Send args... to core via channel in asynchronous message, and waiting for the core-level to reply the message through callback.

name type description
channel string

the request message channel

arg optional ...

whatever arguments the request needs

reply function

the callback used to handle replied arguments

returns:

type: number

session id, can be used in Editor.cancelRequestToCore

cancelRequestToCore ( )

Cancel request sent to core by sessionId

waitForReply
(
  • channel
  • [arg ]
  • reply
  • [timeout ]
)
number

Send args... to core via channel in asynchronous message, and waiting for reply to reply the message through callback.

name type description
channel string

the request message channel

arg optional ...

whatever arguments the request needs

reply function

the callback used to handle replied arguments

timeout optional number

timeout for the reply, if timeout = -1, it will never get expired

returns:

type: number

session id, can be used in Editor.cancelRequestToCore

cancelWaitForReply ( )

Cancel wait for reply by channel and sessionId