JS binding for drawing primitives?


#1

Is there currently any working JS binding for drawing primitives?

I’ve tried cc.DrawNode but can’t get it working and can’t find any documentation. I’ve looked at the source code but to no avail. Need help!

Thanks


#2

i was trying to find info on this as well.
here is the method i used to draw a circle.

var drawnode = cc.DrawNode.create();
this.addChild(drawnode);
drawnode.drawDot( cc.p(100,100), 90, cc.c4f( 1, 0, 0, 1) );

//also has a drawSegment function for lines

also, here is the link autogen bindings reference, it allowed me to see all available ccDrawNode functions.

then search page for ccDrawNode

hope this helps.


#3

That was very helpful. Thanks!

My error was to not add the drawnode to the layer :stuck_out_tongue:

Also, drawSegment was exactly what I was looking for.


#4

If my understanding is correct, new features appear in cocos2d-html5, after the corresponding JSB bindings are generated from the Cocos2d-x project.

So in this case, CCDrawNode is available in cocos2dx from v2.1 onwards, but it is not yet available in cocos2d-html5 2.1. Maybe it was not part of coordinated release.

Is there a documented way to generate JSB bindings for Cocos2d-X or for C++ code in general?
Is there a documented way to go about writing cocos2d-html5 classes for the generated JSB bindings?

TIA.


#5

S G wrote:

If my understanding is correct, new features appear in cocos2d-html5, after the corresponding JSB bindings are generated from the Cocos2d-x project.
>
So in this case, CCDrawNode is available in cocos2dx from v2.1 onwards, but it is not yet available in cocos2d-html5 2.1. Maybe it was not part of coordinated release.
>
Is there a documented way to generate JSB bindings for Cocos2d-X or for C++ code in general?
Is there a documented way to go about writing cocos2d-html5 classes for the generated JSB bindings?
>
TIA.

I believe features are introduced more or less synchronised on the different Cocos2d platforms (IOS, X, HTML5). JSB is just that: JavaScript Bindings of the existing API to native code; it sits on-top of the Cocos2d API whether it’s IOS or X. JSB is not needed in HTML5 since its API is already JavaScript.

Yes, there is a very good document here: (check the readme file): https://github.com/zynga/jsbindings


#6

Thanks Don, my introduction to JSB was also from the same source. Since the description seemed specific to the cocos2d-iphone project and C/ObjC, I was hoping for documentation for the corresponding C*+ project cocos2d-x. Also, I suspect the way JSB is generated for iOS will be different from that for Android? Though overall API maybe almost same.

Coming back to DrawNode, I find lots of changes from cocos2d-html5 v2.1 and v2.1.3. If you look at the CCDrawNode.js under cocos2d/platform/draw_nodes, you will find a new API cc.DrawNodeCanvas and cc.DrawNodewebGL in cocos2d-html5 v2.1.3. So, I expect javascript codebase to change according to the target platform and rendering mode .

The cocos2d-x wiki document has an incomplete stub ‘tbd’ for these two topics http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Javascript_Binding and http://www.cocos2d-x.org/projects/cocos2d-x/wiki/How_to_bind_C*+_to_Javascript