C++ support for Cocos Creator

And here you can compare cocos2d-x (left) vs. Cocos Creator (right).

Labels: RichText support is experimental… as you can see (top labels are RichText). And LineHeight is different (see multilines labels)

Sprites: BlendFunction seems to be broken on Creator (bottom left sprites look Ok on cocos2d-x but not on Creator). Only Raw+untrimmed sprites are supported. Not sure how to handle “trimmed” sprites.


ProgressBar: work in progress (top-left). Label in Buttons seems to have an incorrect vertical position (at least when the label is using TTF fonts).

tmx + particles: working Ok

4 Likes

And here it is:

This is an alpha version. If anyone is interested in testing it, please let me know and I’ll happily help you. Thanks!

16 Likes

I kept fixing some bugs. The limitation of having only a max of 9 tiled sprites is fixed. Now you can have any size:

see bottom right: the tile includes like 32 tiled sprites.

4 Likes

Added spine support. working on native Creator animations.

4 Likes

awesome… you’re great. Do you have a plan to support nested node ?

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.

2 Likes

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

1 Like

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

# https://github.com/ricardoquesada/creator_to_cocos2d
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 -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:

1 Like

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

all:
	-./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/
1 Like

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?
Thanks.

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:

FileUtils::getInstance()->addSearchPath("creator/assets");
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

UPDATE:
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?

Thanks.

@ricardo can you look at my problem?