【发布时间】:2016-04-27 09:12:26
【问题描述】:
我希望能得到一些帮助来解决我现在遇到的问题。
基本上我有一些子弹,然后我有一群快速移动的敌人。敌人有不同的精灵,基本上我想为每个精灵类型分配一个值。例如,如果我说如果生成了一颗钻石并与一颗子弹碰撞,你会得到 10 分,但奇怪的行为是当它发生碰撞时,因为屏幕上的所有敌人都给了 10 分,他们都被摧毁了,而不仅仅是那个。
此外,如果 10 点精灵不在屏幕上,则不给出点数,这是正常的。
请在下面找到我的代码,如果能提供任何帮助,我将不胜感激。谢谢。
//here is my bullets group
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);
},
///here are my enemies
addOneFigura: function(x, y) {
this.figuras = this.add.group();
//these are sprites
this.figuritas = ["figura1","figura2","figura3","figura4","figura5","figura6"];
this.figurita = this.figuritas[Math.floor(Math.random()*6)];
this.figura = this.add.sprite(x,y,this.figurita);
this.figuras.add(this.figura);
this.physics.p2.enable(this.figura, false);
this.figura.body.velocity.y = 75;
this.figura.checkWorldBounds = true;
this.figura.outOfBoundsKill = true;
this.figura.body.setCollisionGroup(this.figurasCG);
this.figura.body.collides(this.bulletsCG, this.collisionBulletMatch, this);
},
//and lastly this is my collision function
collisionBulletMatch: function(figurita, figuritapega) {
if (this.figurita != this.figuritapega){
this.score += 10;
this.scoreText.text = this.score;
this.resetFigura();
}
}
所以基本上当它们发生碰撞时,整个figuras 组就会消失,而不仅仅是一个碰撞。
【问题讨论】:
-
你的
resetFigura函数是什么样的? -
看起来像这样:resetFigura: function(figura) { this.figura.kill(this.figura); },感谢您的回复
标签: phaser-framework