私が今問題を抱えていると私は助けを得ることができたと思っていました。フェイザーP2コリジョン衝突スプライト
基本的に私はいくつかの弾丸を持っている、そして私は速度で移動する敵のグループがあります。敵はスプライトが異なり、基本的にスプライトタイプごとに値を割り当てたいと思っています。たとえば、ダイヤモンドが生成されて弾丸と衝突して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
グループはただ1つの衝突するのではなく、消えます。
あなたの 'resetFigura'関数はどのように見えますか? –
は次のようになります:resetFigura:function(figura){ this.figura.kill(this.figura); }ご回答ありがとうございました – Rafahc