Javascript P2物理体在名为phaserJS的setRectangle()之后不碰撞
我正在制作一个鱼精灵。与foodCollisionGroup发生冲突。鱼吃一些食物。游戏很好。之后,我调整它的大小(增加鱼的大小),它停止与食物碰撞。 我想它可能不会和食物发生碰撞,因为它被称为。 我还有一个问题,fishFoodCount增加了两次。 如何解决这两个问题Javascript P2物理体在名为phaserJS的setRectangle()之后不碰撞,javascript,game-physics,phaser-framework,Javascript,Game Physics,Phaser Framework,我正在制作一个鱼精灵。与foodCollisionGroup发生冲突。鱼吃一些食物。游戏很好。之后,我调整它的大小(增加鱼的大小),它停止与食物碰撞。 我想它可能不会和食物发生碰撞,因为它被称为。 我还有一个问题,fishFoodCount增加了两次。 如何解决这两个问题 Fish.prototype.create = function(x, y){ this.fish = game.add.sprite(x, y, this.spriteName); this.fish.phy
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();
}
使用
setRectangle()
后,需要再次应用冲突组