How can I modify shapes/vertices in Chipmunk with JavaScript?

How can I modify shapes/vertices in Chipmunk with JavaScript?
0.0 0


I’m making a project in Cocos2D-x using Chipmunk physics engine and JavaScript language.
I would like to modify shapes of my objects directly (think about e.g. terrain that you can destruct, you can digg in terrain, you can form terrain like you want). I’ve learned that in C version of Chipmunk there is an “unsafe” module (which has functions like ‘cpPolyShapeSetVerts’) but in JavaScript version I found nothing like this.

Is there possibility to change chipmunk shapes in JS?



Chipmunk js is more of a C++ version of Chipmunk, which differs from the c naming style


It should be… but there is no such function:

     var verts = [40,0,0,0,0,20, 40,20];    
     var shape = new cp.PolyShape(body, verts,pos);     
     shape.setElasticity( 0.5 );
     shape.setFriction( 0.5 );        

     cc.log(shape.setVerts); // logs "undefined"*  

Maybe in another port of Chipmunk? I’m using the version of Chipmunk provided with Cocos2d-x-2.2.1 (I’m developing on Eclipse/ADT and testing on Android device). Maybe unsafe.h was not ported on this version (or maybe there is just no appropriate js-binding to these functions)?

I found some other port, maybe I’ll copy function from there:

PolyShape.prototype.setVerts = function(verts, offset)
altought it would be a JavaScript-side solution so it would be slower than C/C++ solution (If I am not wrong, JavaScript in Cocos2D-x is used only as a scripting language/adapter and critical things like rendering, physics etc. are done on the C++/NDK side, right?)

I’ve read also about autogeometry feature in Chipmunk which could be helpful, but I can’t use that because afaik it is available only in Chipmunk Pro (I’m using the free version).

Properties missing from chipmunk body on compiled JS app

I am using the Chipmunk js found in cocos2d-html5.
It has the setVerts function
you don’t have to worry about the performance, as Chipmunk functions were binded to their C++ counterparts.

Oh, so you are saying this function is not binded to JSB, we could have missed that function, I’ll forward this to our JSB guys, issue #3691 was created for this


Sorry for such a late answer.

It would be nice if this option will appear in the next version of JS bindings (and thanks for taking this into account).