【发布时间】:2016-04-14 12:16:40
【问题描述】:
您好,我正在尝试让我的子弹碰撞,然后在与我的方块碰撞时死亡,但是当我尝试 setCollisionGroup 时,我收到以下错误:
未捕获的类型错误:无法读取未定义的属性“掩码”
它指向我这个代码:
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);
},
一切正常,直到我尝试 setCollisionGroups 然后一切都中断了。任何帮助将不胜感激。
【问题讨论】:
-
你定义
bulletsCG的代码是什么? -
this.bulletsCG = this.game.physics.p2.createCollisionGroup(); this.bloquesCG = this.game.physics.p2.createCollisionGroup();
-
此处完全错误:未捕获的类型错误:无法读取未定义的 phaser.js:87525c.Physics.P2.Body.setCollisionGroup phaser.js:87525(匿名函数) 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
标签: phaser-framework