var Player = cc.Sprite.extend({
在这个里面创建了2个精灵,一个是cc.Sprite方式创建
var player2 = new cc.Sprite("#xxx.png");
player2.setPosition(200, 60);
this.addChild(player2);
另一个是cc.PhysicsSprite方式创建
//1. create PhysicsSprite with a sprite frame name
this.sprite = cc.PhysicsSprite("#xxx.png");
var contentSize = this.sprite.getContentSize();
// 2. init the runner physic body
this.body = new cp.Body(1, cp.momentForBox(1, contentSize.width, contentSize.height));
//3. set the position of the runner
this.body.p = cc.p(this.startX, GG.groundHeight + contentSize.height / 2);
//5. add the created body to space
this.space.addBody(this.body);
//6. create the shape for the body
this.shape = new cp.BoxShape(this.body, contentSize.width - 14, contentSize.height);
//this.shape.setElasticity(0.0); //弹性设置为0,没有效果
//7. add shape to space
this.space.addShape(this.shape);
//8. set body to the physic sprite
this.sprite.setBody(this.body);
this.addChild(this.sprite);
})
将player添加到一个layer中,然后改变layer的位置,结果上面用cc.Sprite创建的会随layer位置改变而改变,而cc.PhysicsSprite创建的不会,不知道为什么,求指导。
