Hi I'm trying to make my bullets collide and then die on collision with my blocks but as soon as I try to setCollisionGroup
I get the following error:
Uncaught TypeError: Cannot read property 'mask' of undefined
and it points me to this code:
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);
});
},
////...............this below is my other colliding group:
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);
},
Everything works until I try to setCollisionGroups then everything breaks. Any help would be greatly appreciated.
bulletsCG
? – James Skemp