我正在尝试找出 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());
因此该项目似乎大部分配置正确。
我一定是错误地加载了场景。我究竟做错了什么?