Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript P2物理体在名为phaserJS的setRectangle()之后不碰撞_Javascript_Game Physics_Phaser Framework - Fatal编程技术网

Javascript P2物理体在名为phaserJS的setRectangle()之后不碰撞

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

我正在制作一个鱼精灵。与foodCollisionGroup发生冲突。鱼吃一些食物。游戏很好。之后,我调整它的大小(增加鱼的大小),它停止与食物碰撞。 我想它可能不会和食物发生碰撞,因为它被称为。 我还有一个问题,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();

}

使用
setRectangle()
后,需要再次应用冲突组