首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >相位器P2碰撞

相位器P2碰撞
EN

Stack Overflow用户
提问于 2017-01-14 00:05:21
回答 1查看 390关注 0票数 0

我正在尝试让我的子弹组与敌人发生碰撞,它们都是一个组,但现在我想添加一个静态块或障碍物,它不会发生碰撞或重叠,或者什么也不会发生,我想要的是当子弹碰撞或重叠时,它会被摧毁,或者至少反弹到障碍物中,请参见下面的代码:

代码语言:javascript
复制
////////////////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();


        
    },

任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2017-01-15 11:19:49

/在这一部分尝试一下,就像这样使用它,我不确定它是否会工作我自己还没有用你的代码尝试过,但试一试,让我知道!

代码语言:javascript
复制
game.physics.arcade.overlap(this.bloque.body.collides, this.bullets, this.collisionBulletBloque, null, this);

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41638783

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档