So the scripts adds the game logic and is thus quite essential. However, what if you are a c++ programmer? I know that you can export your scenes/project to a c++ project, but how can you program the scripts/the game logic in c++. I wish to program the scripts in c++ while being able to apply them to nodes in the cocos creator editor.
Now that I think about it, is it even very beneficial to use Cocos Creator if you use Cocos2d-x(c++)? It just adds so many complexities to the development process when you wish to use C++. This is just sad since Cocos Creator is such a smart tool to ease the whole development process - if you are okay with using cocos2d-js.
1 Like
You would Cocos Creator to layout your UI and then export to C++. This means that if you change your UI in Creator you need to re-export to c++ again. You then use an IDE or text editor to manipulate your c++ files just like you always would.
But then you can still only benefit from 50% of Cocos Creator as opposed to those using cocos2d-js who can drag scripts around, test projects from CC, create prefabs, etc.
Oh and if you have to use it that way, you would need a way to access the nodes added to the UI. I never got that to work successfully though; tried traversing the vector returned from getSceneGraph()->getChildren()
without luck. Or, actually, it detects some children, but says that none of them has any name or size.
And @slackmoehrle, how come I have a Node in my scene that I called âmybackgroundâ (in CC), but when trying to access a child by this name in the scene, no node is found. I am doing the following
creator::CreatorReader* reader = creator::CreatorReader::createWithFilename("creator/game.ccreator");
reader->setup();
Scene* scene = reader->getSceneGraph();
this->addChild(scene);
auto kid = scene->getChildByName("mybackground");
Make sure youâre saving AND exporting the node in CC, and having the node in the Resources folder where cocos can find it. What youâre doing is exactly how Iâd do it too, so it must be something else. It only ever happens like that when the files in my Resources are out of date.
So you have actually succeeded at accessing the individual nodes within the scene from Cocos Creator?
Regarding the resources, when I exported the scene from CC, my resource folder was updated with a .ccreator and a texture folder containing the used texture files.
This is the options I have when exporting
and what is selected.
Yeah, the node comes through exactly like any other node, only itâs not always a 1:1 from CC nodes to c++ nodes because thereâs different names and they structure things different.
Iâm on v0.3 though and I donât have the dynamically loaded ones, but so long as the mybackground
node is in the scene in the editor pane in the top left, it should come through fine. Try making a test node that is just a plain node and then put a breakpoint in CreatorReader::parseNode or something and see what comes through.
Nice, when setting a breakpoint in the parseNode function, it actually shows that it does detect all the nodes with their correctly associated names. However, if this part is all good here in the parseNode function, I wonder why the following does not work
creator::CreatorReader* reader = creator::CreatorReader::createWithFilename("creator/game.ccreator");
reader->setup();
Scene* scene = reader->getSceneGraph();
this->addChild(scene);
auto kid = scene->getChildByName("mybg");
It is clear that the createNode function that the âCanvasâ is correctly loaded. Futhermore, from the breakpoint in the parseNode function, it even shows that a node with the name âmybgâ is parsed.
The node with âmybgâ as its name is a child of the âCanvasâ which is returned from the getSceneGraph()
, so, I really have no clue why it cannot find this âmybgâ node when traversing its children.
For anyone who is up for a challenge (and has a kind soul), here is the resources and classes. The HelloWorldScene.cpp is the file containing the code that tries to access a child of the Canvas (scene) node with the name âmybgâ:
zipping.zip (233.1 KB)
And of course, thanks for your time!
Hmm, totally guessing but if you follow through the calls, is it possible the children arenât added to the Canvas? I never put any of my children in the Canvas, maybe I ran into this same problem a while ago.
Oh, are you looking for the Canvasâ children? scene->getChildByName("Canvas")->getChildByName("mybg")
would probably work if nothing else.
2 Likes
Oh wow! This is quite an ambivalent feeling⌠scene->getChildByName("Canvas")->getChildByName("mybg")
made it work. It was so obvious, yet I missed it. I thought that the reader->getSceneGraph();
returned the âCanvasâ node since it is the main node of the scene. I was clearly mistaken though. It should be illegal for such small things to cause that much trouble :(
We should write more about this in the docs. Iâll add it to my list of changes for the new deployment.
All the Canvas is, as far as I can tell, is just that outline to help understand how large the Scene will be. I donât think itâs a real node because its size is determined by the âscene previewâ size when the scene is created⌠Not positive though.
@slackmoehrle Yeah maybe a note saying something like âif you add children to Canvas, make sure you look through the canvas for childrenâ. Iâm not sure about the canvas not taking children though.