Hi, I’m using Cocos2d-JS v3.6 and I’ve created a PhysicsSprite like this:
var parent = cc.PhysicsSprite(res.cannon_base);
var body = space.addBody(new cp.Body(10, cp.momentForBox(10, 100, 100)));
var shape = new cp.BoxShape(body, 100, 100);
body.setPos(cc.p(300, 300));
parent.setBody(body);
space.addShape(shape);
This is working ok.
But now I’ve added a child to it like this:
var child = new cc.Sprite(res.cannon_pipe);
child.setPosition(50, 50);
parent.addChild(child );
And when the parent object moves in the screen (because of Chipmunk applying the laws of the physics engine to it), the child just stays in the place the parent was created and never moves. Resizing the browser window causes the child to properly be moved to where the parent is.
So, for now, I’ve cobbled together this hack as a temporary “fix”, but something like this shouldn’t be neccesary (and it’s not working when running the compiled app outside the browser):
cc.director.getScheduler().scheduleCallbackForTarget(child, function () {
this.setVisible(false);
this.setVisible(true);
}, 1 / 60, cc.REPEAT_FOREVER);
Anyone got any leads? It appears to be that this used to happen in -x up to v3.5.