Phaser P2碰撞

时间:2017-01-13 16:05:21

标签: phaser-framework

我正试图让我的子弹组已经与敌人发生碰撞,他们都是一个团体,但现在我想添加一个静态阻挡或障碍物,它只是不会碰撞或重叠或什么都没有,我是什么想要的是,当子弹碰撞或重叠时,它会被破坏或者至少反弹到障碍物中,请参阅下面的代码:

////////////////My Bullets//////////These work fine and collide correctly with my enemies.//////

 createBullets: function() {
        
    this.bullets = this.game.add.group();
    this.bullets.enableBody = true;
    this.bullets.physicsBodyType = Phaser.Physics.P2JS;
    this.bullets.createMultiple(100, 'bulletSprite', 0, false);
    this.bullets.setAll('anchor.x', 0.5);
    this.bullets.setAll('anchor.y', 0.5);
    this.bullets.setAll('outOfBoundsKill', true);
    this.bullets.setAll('checkWorldBounds', true); 
        
       
    },
    
    fireBullet: function(){ 

   if (this.bulletTimer < this.game.time.time) {
            this.bulletTimer = this.game.time.time + 500;
            this.bullet = this.bullets.getFirstExists(false);
        if (this.bullet) {
            this.bullet.reset(this.tanke.x, this.tanke.y - 20);
            this.bullet.body.setCollisionGroup(this.bulletCG);
             this.bullet.body.collides([this.figuraCG]);
            this.bullet.body.velocity.y = -3500;
            }
        }

    },


//////This is the block or obstacle this just wont work no matter what I try///////////


makeOneBloque: function(){
        
        
        
        this.bloque = this.game.add.sprite(500, 950, 'Blokes');  
        
         
        this.bloque.enableBody = true;
      
        
        this.game.physics.p2.enable(this.bloque, true);
        
        this.bloque.body.kinematic = true;  
       
        
        this.bloque.body.collides(this.bullets, this.collisionBulletBloque, this); //////I tried overlaps and it just crashes the lvl
       
       
      
       
         


    },
    
      collisionBulletBloque: function(bullet) {
        
         
      
        bullet.sprite.destroy();


        
    },

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

////在这个部分尝试使用它就像这样使用它我不是不可取的如果它工作没有用你的代码自己尝试但是给它一个拍摄让我知道!

game.physics.arcade.overlap(this.bloque.body.collides, this.bullets, this.collisionBulletBloque, null, this);

//////我尝试了重叠,它只是崩溃了lvl