我正在创造一个鱼精灵。与foodCollisionGroup碰撞。鱼吃一些食物。游戏玩得很好。之后我调整它(增加鱼的大小),它停止与食物碰撞。 我认为由于调用了setRectangle,它可能不会与食物发生碰撞。 我有另一个问题,fishFoodCount增加两次。 如何解决这两个问题
Fish.prototype.create = function(x, y){
this.fish = game.add.sprite(x, y, this.spriteName);
this.fish.physicsBodyType = Phaser.Physics.P2JS;
game.physics.p2.enable(this.fish);
this.fish.enableBody = true;
this.fish.anchor.setTo(0.5,0.5);
this.fish.body.collideWorldBounds = true;
this.fish.animations.add('idle', [3 + (this.index * 8)], 10, false);
this.fish.animations.add('move', this.getAnimationFramesArrayFor(this.index) , this.AnimationFrameRate, true);
this.fish.play('idle');
this.fish.body.fixedRotation = true;
}
-------
Fish.prototype.setFishSize = function(width, height){
this.fish.width = width;
this.fish.height = height;
this.fish.body.setRectangle(height/2, width/1.8, width/3.3, 0);
}
-------
Fish.prototype.eatFood = function(fish, food) {
if(this.fishFoodCount > 9){
this.setFishSize(game.width/25, game.height/4);
}
this.fishFoodCount += 1;
food.sprite.kill();
}
答案 0 :(得分:1)
使用setRectangle()
后,您需要再次应用碰撞组。