Gb2ShapeCache for HTML5

Gb2ShapeCache for HTML5
0.0 0


I found this on the web earlier today —

Anyone else using this? Seems to work pretty well — expect when creating shapes with an anchor point that differs from the center point, it has some issues that I’m having trouble identifying, the visual sprite does not match the box2d shape exactly when that’s the case when it’s rotating etc.

Anyone have any experience with this problem?



I am facing a similar issue. sprite.setAnchorPoint has no effect when used with html5, but the same code runs fine with JS bindings.

Also the sprite animation changes its position on the screen on browser but runs fine with JS bindings.


After some trial and error, the problem seems to be with the initial setting of the sprite anchor when creating the body.

Add this in GB2ShapeCache.js under anchorPointForShape
anchorPointForSprite:function (bodyName) {
var body = this._bodies[bodyName];
anchor = cc.p(1-body.*anchorPoint.x,1-body.*anchorPoint.y);
return anchor;

In your create body procedure, when you go to set the anchor point of the sprite, just change


Basically you need to initially set the anchor point of sprite 1-anchor instead of anchor, so I made an explicit function to do it within the file.


In my case, I found the issue was the resource was not preloaded. When I added it to the preload array, it worked fine.