Given that Creator uses a component based model to create its objects, and cocos2d-x has its monolithic structure, it is only possible to support a limited subset of Creator features.
Supported nodes:
Scene
Sprite
Canvas
(but only one per scene)ScrollView
Label
EditBox
ParticleSystem
TiledMap
Button
ProgressBar
(experimental support: unfinished)RichText
(experimental support: unfinished)SpineSkeleton
Animations and other nodes are planned.
Supporting JavaScript scripts would be overkill. If you need JavaScript scripting support, just use Creator.
The Python script to convert .fire to .json is called:
And can be downloaded from this repository:
$ convert_fire_to_json.py \[--cocospath path\] \[--creatorassets\] fire_files_to_parse
--cocospath
: where the assets should be loaded in the cocos2d-x project. It will prepend this path to all the creator assets--creatorassets
: where the default Creator assets are located. Usually they are in the temp
directory of the project's root folderfire_files_to_parse
: it could be one more multiple files. Glob patters are supportedExample:
# should load assets from Resources folder in the game
# Creator default assets are in temp
# The .fire files are located in assets
$ python convert_fire_to_json.py --cocospath Resources --creatorassets temp assets/*.fire
This Github respository also includes a Creator project that is used for testing. For example, this should work:
$ ./convert_fire_to_json.py --cocospath Resources --creatorassets creator_project/temp creator_project/assets/*.fire
The generated .json files will be placed in a folder named "json"
The JSON files are only generated as a temporary file format. It will not be efficient to parse JSON files in a game.
Instead a binary file based on Flatbuffers will be used instead
In order to generate the binary files, the following are needed:
flatc
(flatbuffer) compilerAnd in order to generate the binary files just do:
$ flatc -b CreatorReader.fbs json/*.json
-b
: means generate "binary file"flatc
can be found here:
Afer running flatc
, you will find one or more files with the extension .ccreator
. The .ccreator
files are the binary files that
should be copied to your cocos2d-x project.
You should copy and include the following files to your Cocos2d-x project
.ccreator
filesFinally you have to copy the asset uses by Creator in your project. You should copy:
Just copy them to the directory specified with --cocospath
when convert_fire_to_json.py
was run
You must copy:
// mygame.cpp
#include "CreatorReader.h"
void some_function()
{
CreatorReader* reader = CreatorReader::createWithFilename("creator/CreatorSprites.ccreator");
// will create the needed spritesheets + design resolution
reader->setup();
// get the scene graph
Scene* scene = reader->getSceneGraph();
// ...and use it
Director::getInstance()->replaceScene(scene);
}
A working example can be found here:
Just run "cpp-tests" and select "CreatorTest"