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.