Cocos Creator API

0.7.1

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

Module AssetDB

process: core

Properties

remote Object

The remote AssetDB instance

library String

The library path

Methods

explore
(
  • url
)

process: page

Reveal given url in native file system

name type description
url string

exploreLib
(
  • url
)

process: page

Reveal given url's library file in native file system

name type description
url string

queryPathByUrl
(
  • url
  • cb
)

process: page

Get native file path by url

name type description
url string
cb function

The callback function

queryUuidByUrl
(
  • url
  • cb
)

process: page

Get uuid by url

name type description
url string
cb function

The callback function

queryPathByUuid
(
  • uuid
  • cb
)

process: page

Get native file path by uuid

name type description
uuid string
cb function

The callback function

queryUrlByUuid
(
  • uuid
  • cb
)

process: page

Get asset url by uuid

name type description
uuid string
cb function

The callback function

queryInfoByUuid
(
  • uuid
  • cb
)

process: page

Get asset info by uuid

name type description
uuid string
cb function

The callback function

examples:

Editor.assetdb.queryInfoByUuid( uuid, function ( info ) {
    // info.path
    // info.url
    // info.type
});

queryMetaInfoByUuid
(
  • uuid
  • cb
)

process: page

Get meta info by uuid

name type description
uuid string
cb function

The callback function

examples:

Editor.assetdb.queryMetaInfoByUuid( uuid, function ( info ) {
    // info.assetPath
    // info.metaPath
    // info.assetMtime
    // info.metaMtime
    // info.json
});

deepQuery
(
  • cb
)

process: page

Query all assets from asset-db

name type description
cb function

The callback function

examples:

Editor.assetdb.deepQuery(function ( results ) {
    results.forEach(function ( result ) {
        // result.name
        // result.extname
        // result.uuid
        // result.type
        // result.children - the array of children result
    });
});

queryAssets
(
  • pattern
  • type
  • cb
)

process: page

Query assets by url pattern and asset-type

name type description
pattern string

The url pattern

type string

The asset type

cb function

The callback function

examples:

Editor.assetdb.queryAssets( 'db://assets/**\/*', 'texture', function ( results ) {
    results.forEach(function ( result ) {
        // result.url
        // result.path
        // result.uuid
        // result.type
    });
});

import
(
  • rawfiles
  • destUrl
)

process: page

Import files outside asset-db to specific url folder. The import result will be sent through ipc message asset-db:assets-created

name type description
rawfiles array

Rawfile path list

destUrl string

The url of dest folder

examples:

Editor.assetdb.import( [
     '/file/to/import/01.png',
     '/file/to/import/02.png',
     '/file/to/import/03.png',
], 'db://assets/foobar' );

create
(
  • url
  • data
)

process: page

Create asset in specific url by sending string data to it. The created result will be sent through by ipc message asset-db:assets-created

name type description
url string
data string

examples:

Editor.assetdb.create( 'db://assets/foo/bar/foobar.js', 'var foobar = 0;');

move
(
  • srcUrl
  • destUrl
)

process: page

Move asset from src to dest The moved result will be sent through by ipc message asset-db:assets-moved

name type description
srcUrl string
destUrl string

examples:

Editor.assetdb.move( 'db://assets/foo/bar/foobar.js', 'db://assets/foo/bar/foobar02.js');

delete
(
  • urls
)

process: page

Delete assets by url list The deleted results will be sent through by ipc message asset-db:assets-deleted

name type description
urls array

examples:

Editor.assetdb.delete([
  'db://assets/foo/bar/foobar.js',
  'db://assets/foo/bar/foobar02.js',
]);

save
(
  • url
  • data
)

process: page

Save specific asset by sending string data The saved results will be sent through by ipc message asset-db:asset-changed

name type description
url string
data string

examples:

Editor.assetdb.save( 'db://assets/foo/bar/foobar.js', 'var foobar = 0;');

saveMeta
(
  • uuid
  • metaJson
)

process: page

Save specific meta by sending meta's json string The saved results will be sent through by ipc message asset-db:asset-changed

name type description
uuid string
metaJson string

examples:

Editor.assetdb.save( meta.uuid, JSON.stringify(meta, null, 2));

urlToUuid
(
  • url
)
string

process: core

Return uuid by url. if uuid not found, it will return null.

name type description
url string

returns:

type: string

fspathToUuid
(
  • fspath
)
string

process: core

Return uuid by file path. if uuid not found, it will return null.

name type description
fspath string

returns:

type: string

uuidToFspath
(
  • uuid
)
string

process: core

Return file path by uuid. if file path not found, it will return null.

name type description
uuid string

returns:

type: string

uuidToUrl
(
  • uuid
)
string

process: core

Return url by uuid. if url not found, it will return null.

name type description
uuid string

returns:

type: string

exists
(
  • url
)
string

process: core

Check existance by url.

name type description
url string

returns:

type: string

existsByUuid
(
  • uuid
)
string

process: core

Check existance by uuid.

name type description
uuid string

returns:

type: string

existsByPath
(
  • fspath
)
string

process: core

Check existance by path.

name type description
fspath string

returns:

type: string

isSubAsset
(
  • url
)
boolean

process: core

Check whether asset for a given url is a sub asset.

name type description
url string

returns:

type: boolean

isSubAssetByUuid
(
  • uuid
)
boolean

process: core

Check whether asset for a given uuid is a sub asset.

name type description
uuid string

returns:

type: boolean

isSubAssetByPath
(
  • fspath
)
boolean

process: core

Check whether asset for a given path is a sub asset.

name type description
fspath string

returns:

type: boolean

containsSubAssets
(
  • url
)
boolean

process: core

Check whether asset contains sub assets for a given url.

name type description
url string

returns:

type: boolean

containsSubAssetsByUuid
(
  • uuid
)
boolean

process: core

Check whether asset contains sub assets for a given uuid.

name type description
uuid string

returns:

type: boolean

containsSubAssetsByPath
(
  • path
)
boolean

process: core

Check whether asset contains sub assets for a given path.

name type description
path string

returns:

type: boolean

assetInfo
(
  • url
)
object

process: core

Return asset info by a given url.

name type description
url string

returns:

type: object

{ uuid, path, url, type, isSubAsset }

assetInfoByUuid
(
  • uuid
)
object

process: core

Return asset info by a given uuid.

name type description
uuid string

returns:

type: object

{ uuid, path, url, type, isSubAsset }

assetInfoByPath
(
  • fspath
)
object

process: core

Return asset info by a given file path.

name type description
fspath string

returns:

type: object

{ uuid, path, url, type, isSubAsset }

subAssetInfos
(
  • url
)
array

process: core

Return all sub assets info by url if the url contains sub assets.

name type description
url string

returns:

type: array

[{ uuid, path, url, type, isSubAsset }]

subAssetInfosByUuid
(
  • uuid
)
array

process: core

Return all sub assets info by uuid if the uuid contains sub assets.

name type description
uuid string

returns:

type: array

[{ uuid, path, url, type, isSubAsset }]

subAssetInfosByPath
(
  • fspath
)
array

process: core

Return all sub assets info by path if the path contains sub assets.

name type description
fspath string

returns:

type: array

[{ uuid, path, url, type, isSubAsset }]

loadMeta
(
  • url
)
object

process: core

Return meta instance by a given url.

name type description
url string

returns:

type: object

loadMetaByUuid
(
  • uuid
)
object

process: core

Return meta instance by a given uuid.

name type description
uuid string

returns:

type: object

loadMetaByPath
(
  • fspath
)
object

process: core

Return meta instance by a given path.

name type description
fspath string

returns:

type: object

isMount
(
  • url
)
boolean

process: core

Return whether a given url is reference to a mount

name type description
url string

returns:

type: boolean

isMountByPath
(
  • fspath
)
boolean

process: core

Return whether a given path is reference to a mount

name type description
fspath string

returns:

type: boolean

isMountByUuid
(
  • uuid
)
boolean

process: core

Return whether a given uuid is reference to a mount

name type description
uuid string

returns:

type: boolean

mountInfo
(
  • url
)
object

process: core

Return mount info by url

name type description
url string

returns:

type: object

{ path, name, type }

mountInfoByUuid
(
  • uuid
)
object

process: core

Return mount info by uuid

name type description
uuid string

returns:

type: object

{ path, name, type }

mountInfoByPath
(
  • fspath
)
object

process: core

Return mount info by path

name type description
fspath string

returns:

type: object

{ path, name, type }

mount
(
  • path
  • mountPath
  • opts
  • [cb ]
)

process: core

mount a directory to assetdb, and give it a name. if you don't provide a name, it will mount to root.

name type description
path string

file system path

mountPath string

the mount path (relative path)

opts object

options

  • hide object
    if the mount hide in assets browser
  • virtual object
    if this is a virtual mount point
  • icon object
    icon for the mount
cb optional function

a callback function

examples:

Editor.assetdb.mount('path/to/mount', 'assets', function (err) {
  // mounted, do something ...
});

unmount
(
  • mountPath
  • [cb ]
)

process: core

Unmount by name

name type description
mountPath string

the mount path

cb optional function

examples:

Editor.assetdb.unmount('assets', function (err) {
  // unmounted, do something ...
});