1
votes

I'm trying to figure out the cocos2d Javascript environment. I'm using Cocos Studio v2.1 beta to generate a scene. Right now the scene just has a label so I can know if it worked. I publish it to a Cocos Code IDE project created by Cocos Studio. After some searching, it seems you can load any CSB as a Node by using:

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

Node seems to be the root object for a lot of different things. I'm looking for a way to take this Node and pass it a call to cc.director.runScene(imported);

I tried calling getScene() but that seemed like a stretch. imported shouldn't have a parent that's a Scene, it IS a scene. I have a main.js that looks like this:

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();

When I run the game, it crashes as soon as I run it. Here's the console output:

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

The files listed as missing seem to be misnamed. Those files all exist except with .js extensions instead of .jsc.

The project did run fine when main.js had cc.director.runScene(new HelloWorldScene()); so it seems the project is mostly configured correctly.

I must be loading the Scene incorrectly. What am I doing wrong?

2
Is there any reason why you are going with an old version? I sincirely reccomend you to pick up v3.x and look at the official docs and tutorials ;)Sebastián Vansteenkiste
I'm using what appears to be the latest version of everything. You can see in my output that I'm using cocos-2d-x 3.3. It was the latest at the time of posting. Cocos STUDIO still only seems to be at 2.1-beta.Corey Ogburn
Whoops, I guess I misread, my bad!Sebastián Vansteenkiste

2 Answers

1
votes

Try this:

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

I had to add search path for res directory, otherwise it didn't work.

0
votes

keep default main.js and add following code into 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);

then copy folder that contain images in folder res and paste it outside, near res folder ok. now, you can debug to see how to animation run. contact me with skype koibito10101 and I will tell detail, I can't add picture to decrible for you see @@