使用cc.PhysicsSprite创建的的Sprite无法跟随父Layer移动,代码如下:
var fruit = new cc.PhysicsSprite(res.box_png);
this.layer.addChild(fruit);
var contentSize = fruit.getContentSize();
var body = new cp.Body(5, cp.momentForBox(Number.POSITIVE_INFINITY, contentSize.width, contentSize.height));
body.setPos(cc.p(0, 0));
fruit.setBody(body);
var shape = new cp.BoxShape(body, contentSize.width - 14, contentSize.height-10);
this.shape = shape;
this.shape.setCollisionType(1);
this.shape.setElasticity(1);
this.space.addBody( body );
this.space.addShape( shape );
this.layer.x += 100; //fruit没有跟着移动
如果使用cc.Sprite就没有问题