Import Scene From CocoStudio into code

Hi all, I’m programming on a Mac using CocoStudio 2.0 Beta0 and Cocos2d-x v3.3rc0.

I’m trying to load a simple Scene file with only one button from CocoStudio to xcode project, but without any result.

  1. Create a project directly inside CocoStudio.
  2. Add a button in MainScene.
  3. Click Publish to xCode Project.

in xCode in the init method of HelloWorld class i write this code:

Layer *pUILayer = Layer::create();
cocos2d::ui::Layout *test = dynamic_cast<cocos2d::ui::Layout*>(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("res/MainScene.csb"));
pUILayer->addChild(test);
this->addChild(pUILayer);

this

Layer *pUILayer = Layer::create();
cocos2d::ui::Layout *test = dynamic_cast<cocos2d::ui::Layout*>(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("res/MainScene.csb"));
pUILayer->addChild(test);
this->addChild(pUILayer);

and this

Layer *test = dynamic_cast<Layer*>(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("res/MainScene.csb"));
this->addChild(test);

but anyone of this generate the Scene, otherwise, the app crash always!

If I use widgetFromJsonFile obviously thie generate a isObject exception.
If I use widgetFromBinaryFile it stops at this line:

        rapidjson::Type tType = tpRootCocoNode->GetType(&tCocoLoader);

because the tType is -78.

There’s a simple example or a good documentation for this CocoStudio?
I’ve find a lot of example, but all are different and no one of this example runs.

use this code

auto rootNode = CSLoader::createNode("res/MainScene.csb");
addChild(rootNode);
1 Like

Now it works, Thanks.

What do you find this method?
Do you have any documentation link please?

i am not sure about the updated document, but you can find some example code in cpp-test of version 3.3rc0.

may be this will help
http://www.cocos2d-x.org/reference/native-cpp/V3.3rc0/df/da6/classcocos2d_1_1_c_s_loader.html

Thx!

I tried your code and it works, but the Scene that I create in CocoStudio are small and don’t recognize the normalized size.

Why?

anyone with solution?

I think you have two ways of achieve that the created Scene matches the device size.

A) You could set the design resolution directly to the size on which you desigend the scene in cocosstudio.

B) You set any design resolution and scale accordingly to the resolution on which you created the scene in cocosstudio.

You should prefer B but you can also try A to look if it works.

Hi, the option to publish to Xcode is blank from mine.

Also, i can’t find anywhere to link the CSLoader function.

Is cocostudio is valid if we download from this site, or i have to download whole cocos package from cocos.com?

In Cocos Studio go to Edit Preferences Publish. Can you set a XCode Path there?

No, at the Edit Menu, all i get is option Undo and Redo.
At the preference setting(I’m using Mac) I have only have Environment Settings.
It contains two setting, whether i want to display deprecated widgets or not, or if I want to disable mouse scroll zoom

Check for Updates, and it’s said I have the latest version.
Where do you download cocostudio?

I have it from cocos2d-x.org. But I am also not on a mac but I can set the Cocos Code IDE Path on Edit - Preferences - Publish. So I thought that you need to set a XCode Path.

When you create a new project in cocostudio, you need to check the “generate cocos2d-x project” checkbox and select the engine path of cocos2d-x v3.0 folder. Then you have to choice c++ or lua from “Project language” and create new button!

After that click on file and then publish and publish to xcode.

Actually there is no documentation for programming in cocos2d-x using cocostudio.
I think it is still not appropriate to use this tool.
if someone can do an example project, it would be perfect to share.

@Michael I see no option that I have to set the path anywhere, Cocos IDE/X-Code. I download the studio from cocos2d-x.org

@Wildregar there isn’t any checkbox, any engine path that I can input (I only have Workspace path), or any prefered language.
Here is options the studio give me

And this is the preference setting:
I also have this strange error output.

Sorry to hear that :confused:
This is what I see on windows.

Well, too bad.

I really want to play with cocostudio, include some of these into my next game.
Even I can’t load the .csd file into the editor. I guess I have to wait a little longer.

did you used cocos2d-x 3.3rc0?
The CSLoader is only in 3.3rc0 and above (if I am right?)
https://github.com/cocos2d/cocos2d-x/blob/cocos2d-x-3.3rc0/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp

Try to use Coco Studio 2 for create the project and not Cocos!


Yes, CSLoader works fine, but the resolution of the node isn’t the real resolution of the device multiplied by node’s widgets relative position!

@Wildregar thanks now I’m getting somewhere :smiley:

I create new project from cocostudio and made it into settings just like that. And have ‘Publish to Xcode’ turned on

It’s weird though that my output from cocostudio still

Failed to init GameWindow

I do have some experience from Studio 1.x before, and is it suppose to return some layer? It runs cocostudio simulator just fine. Just like any other samples that it give me. But I can’t open a single .csd from their samples, or from the project I just created.

@Michael Well I clone their repo on GitHub, I sync it last week.CSLoader.cpp did shown in my project navigator in XCode. but when I called CSLoader(here i copy paste the create function at above) and XCode returns error, didn’t know where the function comes from. Does it have some namespace?

I need to

#include "cocostudio/CocoStudio.h"

and then

auto rootNode = CSLoader::createNode("MainScene.csb");
1 Like

Ah thanks for your help @Wildregar and @Michael