Cocos2D-JS 无法加载从 CocosStudio 导出的 json 文件加载、文件、JS、Cocos2D

2023-09-06 14:57:56 作者:无双剑皇

我正在尝试加载从 cocosstudio v2.3.2 导出的 json 文件

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

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

我从 sample-cocos2d-js-scene-gui-master 得到这段代码 问题是,我收到此错误:找不到解析器:未定义 我该如何解决这个问题?我对使用 javascript 很陌生,希望有人可以帮助我.谢谢.

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.

推荐答案

尝试使用 ccs.load("") 新的api.此函数返回表 {node, action} 节点它是你的场景节点"和动作"它是一个时间线动作它是可选的.您的代码如下所示:

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