C++ support for Cocos Creator

C++ support for Cocos Creator
0.0 0


sure. what do you mean by that?


When I use CocosCreator to create a scene. I created some empty nodes like Clouds, Grasses, Obstacles etc … to hold it’s child nodes. After using your tool to convert that scene file, the child nodes are not showing. Without nesting nodes, they work well.


ok. thanks. Sure. I’ll support them. I think I already fixed that a few days ago, but I’ll double check it.


It does work like that. This was one of the issues I reported and you fixed.


I’ve created helper sh script to “publish” changes made in creator:

# https://github.com/ricardoquesada/creator_to_cocos2d

# 1. Convert the .fire files into .json files
python $CTC_PATH/convert_fire_to_json.py  --cocospath Resources --creatorassets creator/temp creator/assets/*.fire

# 2. Compile the newly generated .json files into flatbuffer files
bash -c '$CTC_PATH/bin/flatc -b $CTC_PATH/CreatorReader.fbs json/*.json'

# 3. Copy the generated files to your project
mv *.ccreator Resources/res

# 4. Copy the needed assets to your project
cp creator/assets/*.{png,jpg,plist,tmx,ttf,fnt} Resources/res 2>/dev/null

Tell me what you think about it :wink:


I have a similar script as well :slight_smile: It is a Makefile file

	-./convert_fire_to_json.py --cocospath creator/assets --creatorassets creator_project/temp creator_project/assets/*.fire
	-flatc -c -b CreatorReader.fbs json/*.json
	mv *.h ~/path/to/cocos2d-x/tests/cpp-tests/Classes/CreatorReaderTest/
	mv *.ccreator ~/path/to/cocos2d-x/tests/cpp-tests/Resources/creator/


I’m trying very hard to get it working…
I’ve tried your copying your “reader” into my cocos2d-x project (fresh new one), however I couldn’t compile app… I was getting several errors about missing stuff.
So instead I downloaded your cpp-tests and they’re working except test scene 3 (I’ve sent an issue on github on this) and I’ve realised reader classes are different. So I’ve got this ones to my project.

From my project your tests scenes are working (except 3 again), however my own scene (just a few sprites, no fancy stuff) still doesn’t work… I’m getting EXC_BAD_ACCESS in line 403 (CreatorReader::parseSprite).

I suspect reader from your cpp-tests and from main github page are from a different commit.

My scene has 4 sprites (4x png file), so in total I have 5 files (these 4 + scene.ccreator).
My questions are:

  • do I need .meta files? Probably not, but just asking. I’ve tried adding them, but it keeps crashing.
  • am I forced to have these files in Resources/creator directory. From my script above I was copying them into Resources/res directory and this was causing even your examples not working anymore.
  • do images needs to be in creator/assets directory?
  • if I’m doing all this stuff right, why it keeps crashing? What I am missing?


Hey @ricardo
Can you tell me how the C++ support is added into Cocos Creator?
What i mean is Creator made with entity-component structure so C++ support will be like that only?
if so then coding will be different compare to normal cocos2d-x c++ project, correct?


Ok - I found out what’s causing the problem. These 4 pngs cannot be found. I’ve manually added them before calling CreatorReader like this:

auto sfc = SpriteFrameCache::getInstance();
sfc->addSpriteFrame(Sprite::create("play_tlo.png")->getSpriteFrame(), "play_tlo");
sfc->addSpriteFrame(Sprite::create("btn_play.png")->getSpriteFrame(), "btn_play");
sfc->addSpriteFrame(Sprite::create("play_postacie.png")->getSpriteFrame(), "play_postacie");
sfc->addSpriteFrame(Sprite::create("tytul.png")->getSpriteFrame(), "tytul");

And then scene loads without a problem.
But why is that happening? I don’t have to do this for sample scenes that you provided.


AFAIK, c++ support only for scene editing. You set up UI, some background element, map layout… You need to implement gameplay code with normal c++ workflow

entity-component structure is supported for js (and lua i guess)


Okay, lets wait for @ricardo reply


It is as @nbtthief said.

it doesn’t support all Creator features since it would be a huge task since:

  • creator is optimized for JS
  • creator added its own classes/components

so “c++ support” means that a Creator’s Scene can be loaded in C++ but certain limitations:

  • no JS code
  • only the built-in nodes: Sprite, ScrollView, Buttons, etc…
  • Animations


I’ve been very busy these past weeks. Creator Animations are almost ready… I still have to fix a few bugs and finish a few things here and there.


So basically it will behave like UI / scene editor mostly? (including all UI )
Even that will be great too.
Can you tell us what will be the flow for that? Like first what we have to do? How we have to load from code, etc?



@ricardo can you look at my problem?


The current workflow is described here: https://github.com/ricardoquesada/creator_to_cocos2d
but we are working on polishing it. the idea is that it will be built-in in Cocos Creator. Kind of “Export -> cpp” and wiill generate all the needed files.

Not sure. I will need more info.
I’m not doing anything special in my example:

mmm… wait. I think you are exporting the assets with this:

$ ./convert_fire_to_json.py --cocospath creator/assets --creatorassets creator_project/temp creator_project/assets/*.fire

so, all the assets generated by the script have the “full path” embedded in them.
If you add your own assets in that directory, they won’t be found automatically.


Thanks for reply.
Around when it will be available in Creator?


Looking forward to using this. After looking at the source, I have a few concerns. Will I be able to assign custom classes to nodes in my scene? Will the widget layout information like percent width/position etc… be transferred to C++ or just the relative values?

Thanks. I can’t wait to finally upgrade from cocos studio to creator, but these would be blocking issues for me.


I’m exporting my scene with pretty much the same parameters as you.

This is my current “publish” script:

# https://github.com/ricardoquesada/creator_to_cocos2d
#add to ~/.bash_profile:
#export CTC_PATH=/Users/piotr/Documents/pierdoly/creator_to_cocos2d

# 1. Convert the .fire files into .json files
python $CTC_PATH/convert_fire_to_json.py  --cocospath Resources --creatorassets creator/temp creator/assets/*.fire

# 2. Compile the newly generated .json files into flatbuffer files
bash -c '$CTC_PATH/bin/flatc -c -b $CTC_PATH/CreatorReader.fbs json/*.json'

# 3. Copy the generated files to your project
mv *.ccreator Resources/creator

# 4. Copy the needed assets to your project
cp creator/assets/*.{png,jpg,plist,json,atlas,tmx,ttf,fnt} Resources/creator/assets 2>/dev/null

These assets are on the scene and are exported with it. I don’t complain about some additional ones.

How are you exporting assets for tests and how is your file structure looking?


soon I guess :slight_smile:
don’t know the exact date, but it will be included as a plugin

a) No. We are using FlatBuffers, and you can’t create an “unknown” node… unless you modify the flatbuffer schema and add your own node there.
b) I didn’t understand the question… but it should a “WYSIWYG”. If not it is a bug.

I’m not exporting the assets… I’m just saving the file and then the python script pre-pends the cocos path to them.
According to your script, all the Creator resources (and only them) must be under “Resources”.
If you place an “external” resource under “Resources” you should prepend “Resources/” manually or just include “Resources” in the search path.