Import Scene From CocoStudio into code

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

@GulperEeL np ^^ … if you can import a scene with the correct resolution maybe post here the code please :smiley:

I still have not succeeded

I will, but apparently I still have this cocostudio bug, in which I can’t load csd file to cocostudio(spit out Failed to init GameWindow ), can’t publish with xcode(the label turned on, but it returns nothing). I’ll let you know If I have solved the problem :smile:

@GulperEeL Seems to be your graphics drivers are not properly installed; are may be old

I guess so, I’m running on Mac, the GPU is ATI Radeon HD 4670 256 MB.

there are several others who report this if i search on google, in cocoachina
or cocostudio 2 feedback Cocos Studio 2 Feedback

My computer also run cocostudio v1.x just fine though

Hi,
It’s not working for me. It’s saying that file cannot be found. Tried combinations with “…/” and no still no luck. The only way I found is to give full absolute path, then it’s not crashing, however… I cannot see the scene. Just black screen.

Any tutorial for this?

Not the cute solution, but here is how I loaded an scene, scaled and play the animation:

Size visibleSize = Director::getInstance()->getVisibleSize(); //get the visible size   
auto spriteCache = SpriteFrameCache::getInstance(); //To read from a plist
spriteCache->addSpriteFramesWithFile("RaptwareLogo.plist"); //Read the plist
auto logo = CSLoader::createNode("RaptwareLogo.csb"); //read the scene
float scale = MIN(visibleSize.width/480,visibleSize.height/320); //get the which scale to use
logo->setScale(scale); // scale it
logo->setPosition(Vec2((visibleSize.width-scale*480)/2,(visibleSize.height-scale*320)/2)); // move everything so it is centered
this->addChild(logo); // Show the scene

auto timeline = CSLoader::createTimeline("RaptwareLogo.csb"); // load the time line
logo->runAction(timeline); //set the timeline action
timeline->gotoFrameAndPlay(0,true); //Actually play it

Hope this works for you :smiley:

1 Like

Hi All,

I have just started using Cocos Studio. I have created a UI project and added an ImageView on canvas. I can see the properties of the ImageView. But I am unable to figure out how to change default image for ImageView (in UI Editor)? Similarly I could not change the image for Sprite (in Scene Editor)? It should be simple but somehow i could not be able to figure it out.

I am using Cocos Studio 1.6.0.0 on Windows with Cocos2d-x v 2.2.6.

Thanks,

I don’t understand:

jsb.fileUtils.addSearchPath(“res”);
var node = ccs.csLoader.createNode(“res/MainScene.csb”);
this.addChild(node);

in js it works.

cc.FileUtils:getInstance():addSearchPath(“res”);
local node = cc.CSLoader:createNode(“res/MainScene.csb”);
scene:addChild(node);

works for lua too.

And in c++:
FileUtils::getInstance()->addSearchPath(“res”);
auto node = CSLoader::createNode(“res/MainScene.csb”);
this->addChild(node);

Doesn’t work.
cocos2d: fullPathForFilename: No file found at res/MainScene.csb. Possible missing file.

Why? Also there’s one troublesome thing with createNode. Nodes must have anchors in (0, 0) or they’ll be misplaced on the screen (unless you will set them correct anchor points in code - the same as in the cocos studio).

Edit:
I get this PARTIALLY working.
So, I switched from mac os to windows and discovered that it’s just working. It’s because in xcode you need to add res directory into your project, which I forgot to do.
However I’ve got a problem with windows phone. There you have to add your assets into assets folder. I did that and I can load sounds or images, however I can’t load csb file. It’s just saying that file does not exist. It’s like visual studio is not packing it into binary. When I renamed .csb extension to .jpg it said file exists (using FileUtils::getInstance()->isFileExist(“MainScene.jpg”); ). Renamed it back to .csb and poof, does not exist. Ofc I tried to load it from csloader, when it had .jpg extension, but it doesn’t seem to be working.

This is really crucial to be. Help!

Edit2:
I finally did it! You need to change properties of csb file to ‘always copy’ and ‘content’.
Also if you use visual studio 2013 you can open win 8.1 universal project (which contains both desktop and mobile) and just not use wp8-xaml project.

Hi,
Have you found the solution for the anchor points issue you mentioned? I have the same on my mac (on win it worked well) and it’s a little annoying.

Thanks

Dunno what causes it. Yeah on windows it just works (in c++, not in js as I remember correctly). If your anchors are wrong you have to:
use only (0, 0) anchors OR set anchor points in code for the same as you set up in coco studio.

Ok, thanks, Unfortunately for me it’s not the solution as I need anchor points to display dynamic labels correctly (ex. aligned to the right or to the center). Also I have quite big GUI so setting anchor points in code will be very hard.
Anyway, I’m going to wait for the next cocostudio release.

But you just need set the same anchors as in cocos studio.
So if you add something on cocos editor and set anchor to let’s say (0,5; 0,5) you need to do this in code too like this:
root->getChildByName(“something”)->setAnchorPoint(0.5, 0.5); so that’s one line per item and it should work with your dynamic labels too.

Hi, I have the same problem like you @makalele, I cant find the .csb path in my project. I’ve solved it! :slight_smile:

@makalele
did u use VS2013 update 3 above?
as I cannot run Win8.1 universal project in VS2013 ultimate.
The error is the same with using coco2d-x 3.2.
I used the old version of csb included in cpp-test version 3.2.

At first I used your method by setting it to “Copy Always” and “Content”, it can read it but the error occurred to “Misc\music_logo.mp3”.
It said there is no such file.
I used again your method, but it never runs. Always exit.

Then I tried using win8 xaml made by version 3.3.
I used the same file “FishJoy2.csb” provided by cpp-tests 3.2 and using

auto node = CSLoader::createNode(_filePath);
addChild(node);

I added library:

include “cocostudio/CocoStudio.h”

The error always come in other libraries.
I forgot what it is.

Really confusing.
Any help, please?

No problem I already know the solution.
This is my result.

Cocos Studio 2 Feedback

Have a problem with loading scene created in cocostudio 2.+.
In cocostudio i have designed the scene to be adaptive, i.e. use pins, percent sizes and positions. So it should adapt it’s layout on different devices. And if i change design size right inside cocostudio - it adapts good.

But if i load this scene from the code it will have a fixed size that was setup in cocostudio (480x320). So if this scene loaded of iphone 5 or 6 - black spaces added to the right.

How scene can be loaded to fit the whole screen? Even old cocosbuilder can handle this situation properly.

Thanks.

I’m having a similar issue, pin and sizing options work great in the CocosStudio Editor but when resizing at runtime the behaviour is lost. Is this likely to be fixed soon?

Edit: good solution here

Currently you have to call this code :

auto rootNode = CSLoader::createNode( "Scene.csb" );
auto size = Director::getInstance()->getVisibleSize();
rootNode->setContentSize(size);
ui::Helper::doLayout(rootNode);
1 Like