Hallo Ich versuche, meine Kugeln kollidieren zu machen und dann auf Kollision mit meinen Block sterben, aber sobald ich zu setCollisionGroup
versuche ich die folgende Fehlermeldung erhalten:Phaser P2 setCollisionGroup
Uncaught TypeError: Cannot read property 'mask' of undefined
und er zeigt mich dieser 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 unten ist meine andere kollidierenden Gruppe:
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);
},
Alles funktioniert, bis ich versuche, CollisionGroups zu setzen, dann bricht alles zusammen. Jede Hilfe würde sehr geschätzt werden.
Was ist Ihr Code, der 'bulletsCG' definiert? –
this.bulletsCG = diese.game.physics.p2.createCollisionGroup(); this.bloquesCG = diese.game.physics.p2.createCollisionGroup(); – Rafahc
Vollständiger Fehler hier: Uncaught TypeError: Kann Eigenschaft 'mask' von undefiniertem phaser.js nicht lesen: 87525c.Physics.P2.Body.setCollisionGroup phaser.js: 87525 (anonyme Funktion) level1.js: 120c.Group.forEach phaser.js : 32664BasicGame.Game.createBullets level1.js: 119BasicGame.Game.create level1.js: 57c.StateManager.loadComplete phaser.js: 29240c.Loader.finishedLoading phaser.js: 71446c.Loader.processLoadQueue phaser.js: 71403c.Loader. asyncComplete phaser.js: 71476c.Loader.fileComplete phaser.js: 72323a.data.onload – Rafahc