1

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

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

Node 似乎是许多不同事物的根对象。我正在寻找一种方法来获取这个节点并将其传递给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());因此该项目似乎大部分配置正确。

我一定是错误地加载了场景。我究竟做错了什么?

4

2 回答 2

1

尝试这个:

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

我必须为 res 目录添加搜索路径,否则它不起作用。

于 2015-01-13T11:54:02.907 回答
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联系我,我会告诉细节,我无法将图片添加到您看到@@

于 2015-01-29T11:32:41.927 回答