[SOLVED] [CREATOR CPP] Custom Class Integration

Hello,

In a quest to add custom class functionality to Cocos Creator exported, I’ve done some changes in the CreatorReader.h/.cpp.

In order to create standalone objects (with custom class) from the scene
e.g. CustomLayer class in my example project.
Instead of reading the entire scene, I’ve used getNodeGraph()
But I face the following issue as mentioned below -

If I do like this in my AppDelegate.cpp

CustomScene* scene = CustomScene::createFromCCreator();
scene->testUI();
director->runWithScene(scene);

It works fine for me. My custom class integration is functional as expected.

But, If I try to read a node, from the .ccreator file, and as child to a Scene, like this -

Scene* myScene = Scene::create();
CustomLayer* myLayer = CustomLayer::createFromCCreator();
myLayer->test();
myScene->addChild(myLayer);
director->runWithScene(myScene);

See, my buttons are completely non-responsive.

I’ve tried to check for touch issues, listeners etc, but couldn’t figure out much.
If you could help me identify the issue, that would be great.
You could run the project directly, in Xcode with target platform as Mac.

Used:
cocos2d-x 3.16 and Creator 1.9
I’ve added the github link here.

UPDATE:
Well, I’ve found the issue that was causing the behaviour.
In my function getNodeGraph() of file CreatorReader.h
While making the searchNode standalone, I had cleaned up the listeners as well.
like this -

searchNode->removeFromParentAndCleanup(true);

But, it should be instead like this -

searchNode->removeFromParentAndCleanup(false);

That fixed the problem. :slight_smile:

Are you using the newest Creator to CPP reader? There was a new version released a short time ago. C++ and Lua support for creator v0.4 released

Hi Jason,

I used the package from this github link
The one I am using from the above github link, contains the pull request.

I will check the cpp-empty-tests now.

If anyone want to use this, here’s what I’ve changed

Earlier, I have been programming cocos2dx games using Cocos Studio.
The concept of Custom Class and ability to create a separate Layer csd file was pretty handy.

Since, Cocos Creator has no functionality to directly read CustomClass name, neither to export only Layer files. I’ve been working to bridge this issue.

These are the following things that I’ve added to the project -

  • Used specific naming convention i.e “Layer_ClassName_NodeName” in nodes, that I can attach custom class. The reason behind it to create a runtime class of that type from the string, directly while reading the ccreator file. Ex - CustomLayer class in my project. (Used Factory Pattern).
    NOTE: the layer node in creator, should only contain the Node component, else this would fail.

  • Subclassed the reader to create the Scene of custom type, while reading from the ccreator file directly. Ex - CustomScene class in my project.
    So, by doing this the CustomLayer object would be created, while reading the Scene
    or if you want to create objects in the runtime, it will do so.

  • Wrote meta codes, to handle for - CustomScene, CustomLayer, ButtonClickEvent etc.

This is the github link of my project.
I’ve used - Cocos2dx 3.16, Creator 1.9 and the latest pull from this repo as of today.

1 Like