Cocos Studio And Cocos Code workflow

Hello all,

I am back to cocos2D after quite some years and things have changed considerably so i am starting all over again.
I downloaded Cocos Studio (latest ver) and Cocos Code (latest version too). After quite some effort i managed to get them to work together.
I created the project through Code as the other way around doesn’t seem to work…
The project type is Cocos2D-JS
I created a very simple screen in studio where i got a background image and two sprites.
I managed to export the project (it is now called publish … cost me about an hour to figure) and inside cocos code when running the project everything is fine. I can see the scene exactly as i designed it.

Wheee! Great!

But where is the code ? I want to add some code to handle clicking on one of the two sprites (i know that the background is technically a sprite too). Where can i do this inside Code ?
Do i have to create separate .js files ?
How do i tell the sprites the must receive clicks/touches etc ?

Thank you for your support …

After published the project from Studio, the file save as JSON type in the published directory (usually “res” folder).
Then when you hit Play button, Cocos framework parse it and call some methods to manipulate the scene from what you’ve designed from Studio.
If you want to modify the scene using code, you must be load the JSON in to the cocos project that created by Code IDE or CC Command.
Here is the snippet how to implement JSON file into your project:

var node = ccs.load(<filePath>);
this.addChild(node);

Then you can get access to each component that you named in Studio by use this:

var button = ccui.helper.seekWidgetByName(root, "buttonName");

You can also get it by tag (in the properties of each object has Tag)

var button = node.getChildByTag(<tagNumber>);

Great.

Thank you for your help.

I can access my sprites and move them around, i also found out how to detect clicks / touches etc.

But what if i want to have a sprite as an object of a class derived from sprite.
I.e. i made a class called SuperSprite that is a subclass of Sprite. How can i specify that one of my objects should be an instance of SuperSprite rather than the normal sprite ?

Thank you.

I’m not sure, but for me, when I want to create something that need customizing, I’ll create it by hand code instead of using Studio.