Phaser P2 设置碰撞组
Phaser P2 setCollisionGroup
嗨,我正在尝试让我的子弹发生碰撞,然后在与我的方块碰撞时死亡,但是当我尝试 setCollisionGroup
时,我收到以下错误:
Uncaught TypeError: Cannot read property 'mask' of undefined
它指向我这段代码:
createBullets: function(){
//Bullets
this.bullets = this.add.group();
this.bullets.enableBody = true;
this.bullets.physicsBodyType = Phaser.Physics.P2JS;
this.bullets.createMultiple(500, 'bullet', 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);
this.bullets.forEach(function(bullet){
bullet.body.setCollisionGroup(this.bulletsCG); <-------This line
bullet.body.collides(this.bloquesCG);
});
},
////......下面是我的另一个碰撞组:
addOneBloque: function(x, y) {
this.bloque = this.add.sprite(x,y,'bloque');
this.physics.p2.enable(this.bloque, false);
this.bloque.body.velocity.x = -200;
this.bloque.checkWorldBounds = true;
this.bloque.outOfBoundsKill = true;
this.bloque.body.setCollisionGroup(this.bloquesCG);
this.bloque.body.collides(this.bulletsCG, this.resetBullet, this);
},
一切正常,直到我尝试设置 CollisionGroups,然后一切都崩溃了。任何帮助将不胜感激。
我在错误的地方声明,谢谢大佬。
嗨,我正在尝试让我的子弹发生碰撞,然后在与我的方块碰撞时死亡,但是当我尝试 setCollisionGroup
时,我收到以下错误:
Uncaught TypeError: Cannot read property 'mask' of undefined
它指向我这段代码:
createBullets: function(){
//Bullets
this.bullets = this.add.group();
this.bullets.enableBody = true;
this.bullets.physicsBodyType = Phaser.Physics.P2JS;
this.bullets.createMultiple(500, 'bullet', 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);
this.bullets.forEach(function(bullet){
bullet.body.setCollisionGroup(this.bulletsCG); <-------This line
bullet.body.collides(this.bloquesCG);
});
},
////......下面是我的另一个碰撞组:
addOneBloque: function(x, y) {
this.bloque = this.add.sprite(x,y,'bloque');
this.physics.p2.enable(this.bloque, false);
this.bloque.body.velocity.x = -200;
this.bloque.checkWorldBounds = true;
this.bloque.outOfBoundsKill = true;
this.bloque.body.setCollisionGroup(this.bloquesCG);
this.bloque.body.collides(this.bulletsCG, this.resetBullet, this);
},
一切正常,直到我尝试设置 CollisionGroups,然后一切都崩溃了。任何帮助将不胜感激。
我在错误的地方声明,谢谢大佬。