Cocos2D-JS can't load json file exported from CocosStudio

懵懂的女人 提交于 2019-12-11 01:25:20

问题


I'm trying to load a json file exported from cocosstudio v2.3.2

var myScene = ccs.sceneReader.createNodeWithSceneFile('res/Scene.json');

I got this code from sample-cocos2d-js-scene-gui-master
The problem is, i get this error: Can't find the parser : undefined

How do i fix this issue?
I'm very new to using javascript and I hope someone can help me with this. Thank you.


回答1:


try to use ccs.load("") It's new api. This function returns table {node, action} node it's your scene "node" and "action" it's a time line action it's optional.

Your code would look like this:

var sceneRes = ccs.load("res/Scene.json");
this.addChild(sceneRes.node);

And if you want use the action, just run it for node.

sceneRes.node.runAction(sceneRes.action);
sceneRes.action.gotoFrameAndPlay(0, true);

Hope this help, and sorry for my english



来源:https://stackoverflow.com/questions/35035027/cocos2d-js-cant-load-json-file-exported-from-cocosstudio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!