运行CocosStudio中生成的场景?

时间:2015-01-09 16:53:46

标签: javascript cocos2d-x cocos2d-js cocostudio

我试图找出cocos2d Javascript环境。我使用Cocos Studio v2.1 beta生成场景。现在这个场景只有一个标签,所以我可以知道它是否有效。我将它发布到Cocos Studio创建的Cocos Code IDE项目中。经过一些搜索后,您似乎可以使用以下命令将任何CSB作为节点加载:

var imported = ccs.csLoader.createNode("res/MainScene.csb");

Node seems to be the root object for a lot of different things.我正在寻找一种方法来获取此节点并将其传递给cc.director.runScene(imported);

我试着打电话给getScene(),但这似乎是一个延伸。 imported不应该有一个父母是一个场景,它是一个场景。我有一个看起来像这样的main.js:

cc.game.onStart = function(){
    cc.view.adjustViewPort(true);
    cc.view.setDesignResolutionSize(800, 450, cc.ResolutionPolicy.SHOW_ALL);
    cc.view.resizeWithBrowserSize(true);
    //load resources
    cc.LoaderScene.preload(g_resources, function () {
        var imported = ccs.csLoader.createNode("res/MainScene.csb");
        cc.director.runScene(imported);
    }, this);
};
cc.game.run();

当我运行游戏时,它会在我运行时立即崩溃。这是控制台输出:

Console: listening on  0.0.0.0 : 6050
Console: listening on  0.0.0.0 : 6060
Ready for GLSL
Ready for OpenGL 2.0

{
    gl.version: 2.1.0 - Build 8.15.10.2622
    gl.supports_NPOT: true
    cocos2d.x.version: cocos2d-x 3.3
    cocos2d.x.compiled_with_profiler: false
    cocos2d.x.build_type: DEBUG
    cocos2d.x.compiled_with_gl_state_cache: true
    gl.max_texture_size: 8192
    gl.vendor: Intel
    gl.renderer: Intel(R) HD Graphics
    gl.max_texture_units: 16
    gl.supports_ETC1: false
    gl.supports_S3TC: true
    gl.supports_ATITC: false
    gl.supports_PVRTC: false
    gl.supports_BGRA8888: false
    gl.supports_discard_framebuffer: false
    gl.supports_vertex_array_object: true
}


cocos2d: fullPathForFilename: No file found at script/jsb_debugger.jsc. Possible missing file.
cocos2d: fullPathForFilename: No file found at script/debugger/DevToolsUtils.jsc. Possible missing file.
cocos2d: fullPathForFilename: No file found at script/debugger/core/promise.jsc. Possible missing file.
cocos2d: fullPathForFilename: No file found at script/debugger/transport.jsc. Possible missing file.
cocos2d: fullPathForFilename: No file found at script/debugger/actors/root.jsc. Possible missing file.
cocos2d: fullPathForFilename: No file found at script/debugger/actors/script.jsc. Possible missing file.
cocos2d: fullPathForFilename: No file found at script/debugger/main.jsc. Possible missing file.
cocos2d: fullPathForFilename: No file found at script/jsb_boot.jsc. Possible missing file.
suffix = csb
textureSize = 0
classname = Node
size = 1
classname = Text
callBackName  cannot be found
size = 0
child = 0882F950

列为缺失的文件似乎被错误命名。这些文件都存在,除了.js扩展名而不是.jsc。

当main.js有cc.director.runScene(new HelloWorldScene());时项目运行正常,所以看起来项目大部分配置正确。

我必须正确加载场景。我做错了什么?

2 个答案:

答案 0 :(得分:1)

试试这个:

jsb.fileUtils.addSearchPath("res");
var node = ccs.csLoader.createNode("res/MainScene.csb");
this.addChild(node);

我必须为res目录添加搜索路径,否则它无法正常工作。

答案 1 :(得分:0)

保持默认 main.js 并将以下代码添加到 app.js

var node=ccs.csLoader.createNode("res/cat_queen.csb");
var node_action=ccs.actionTimelineCache.createAction("res/cat_queen.csb");
node.runAction(node_action);
node.attr({scale:1.5,x:size.width/2,y:size.height/3,});
node_action.gotoFrameAndPlay(0,60, true);
this.addChild(node);

然后复制包含 res 文件夹中图像的文件夹并将其粘贴到 res 文件夹附近 好。现在,您可以调试以查看如何运行动画。 请通过skype koibito10101与我联系,我会告诉您详细信息,我无法添加图片以便您查看@@