cocos2d-js v3.8, How can I use the scene exported from cocos studios in to my project?

Hi, I’m new with cocos2d, but I having study a lot, I’m following a tutorial from you to use the json exported from Cocos Studio to my project ( http://www.cocos2d-x.org/docs/tutorial/studio/parkour-game-with-cocostudio/chapter3/en ), but I’m using cocos2d-x v3.8, and there are some diferences.

I have a menuScene that has 3 layers,(the background layer, the animation layer and the HUD layer), the login buttom and the text fields for the user name are in the HUD layer.

the problem is in the follow code when I try to load the Json:

//add cocostudio scene to game
var gameSceneNode = cc.CCSSceneReader.getInstance().createNodeWithSceneFile(Scene_GameScene);
this.addChild(gameSceneNode);

    var pAudio =gameSceneNode.getComponent("Audio");
    pAudio.playBackgroundMusic(pAudio.getFile(), pAudio.isLoop());
    var gameComRender =  gameSceneNode.getChildByTag(1);
    var gameSceneComponent = gameComRender.getComponent("mainMenuLayer");
    var uiLayer = gameSceneComponent.getNode();
    var startButton = uiLayer.getWidgetByName("startButton");
    startButton.setTouchEnabled(true);
    startButton.addTouchEventListener(this.startBtnCallFunc ,this);

it send me the following error:

Uncaught TypeError: Connot read property ‘getInstance’ of undefined
cc.Scene.extend.onEnter
(anonymous function)
cc.Director.cc.Class.extend.setNextScene
cc.Director.cc.Class.extend.drawScene
cc.DisplayLinkDirector.cc.Director.extend.mainLoop
callback

Can some body help me please. I need to can control the button and the textField to can programate to send the player to the gameScene.

Hi, I did it!!! and I write the answer for some one it’s looking the same thing… the solution to my proyect was the following code:

Here is app.js to use the scene created by Cocos Studios.

var MenuLayer = cc.Layer.extend({
sprite: null,
ctor: function () {
this._super();

    var size = cc.winSize;
    var mainScene = ccs.load(res.MainScene_json);
    this.addChild(mainScene.node);
    var childNode3 =  mainScene.node.getChildByName("ProjectNode_3");
    var startButton = childNode3.getChildByName("btnLogin");
    startButton.setTouchEnabled(true);
    startButton.addTouchEventListener(this.loginBtnCallFunc ,this);
},
//click btn of start.
loginBtnCallFunc:function(pSender)
{
    cc.log("==startBtn clicked");
    cc.director.pushScene(new GameScene());
}

});

var MenuScene = cc.Scene.extend({
onEnter:function () {
this._super();

    var layer = new MenuLayer();
    this.addChild(layer);
}

});

I hope I can help some one like me (Beginner in cocos2d) with it. :smile:

1 Like