我正在尝试让我的子弹组与敌人发生碰撞,它们都是一个组,但现在我想添加一个静态块或障碍物,它不会发生碰撞或重叠,或者什么也不会发生,我想要的是当子弹碰撞或重叠时,它会被摧毁,或者至少反弹到障碍物中,请参见下面的代码:
////////////////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();
},
任何帮助都将不胜感激。
发布于 2017-01-15 11:19:49
/在这一部分尝试一下,就像这样使用它,我不确定它是否会工作我自己还没有用你的代码尝试过,但试一试,让我知道!
game.physics.arcade.overlap(this.bloque.body.collides, this.bullets, this.collisionBulletBloque, null, this);/我尝试重叠,但它只是使lvl崩溃
https://stackoverflow.com/questions/41638783
复制相似问题