簡単にするために、私はゲームを持っています。私は車に壁を打つようにしています。私は検索を試みましたが、以下に示すようにいくつか試してみましたが、なぜ私はそれを動作させることができないのか分かりません。ここでなぜ私の衝突検出がフェイザーで機能していませんか?
は私のcreate
関数のコードです:
create: function() {
game.physics.startSystem(Phaser.Physics.ARCADE);
this.carSprite = game.add.sprite(game.world.centerX, game.world.centerY, 'car');
game.physics.arcade.enable(this.carSprite);
this.timer = game.time.events.loop(300,
this.addRoad, this);
}
はその後、私のupdate
機能に:私は
addOneRoadSection: function (x, y) {
this.scoreCalculator += 1;
if (this.scoreCalculator == 10) {
this.scoreCalculator = 0;
this.wallSprite = game.add.sprite(x + 100, y, 'wall');
game.physics.arcade.enable(this.wallSprite);
this.wallAnimation = this.wallSprite .animations.add('wallAnimation');
this.wallSprite.animations.play('wallAnimation', 30, true);
this.wallSprite.body.velocity.y = 100;
this.wallSprite.checkWorldBounds = true;
this.wallSprite.outOfBoundsKill = true;
}
}
:
update: function() {
game.physics.arcade.overlap(this.carSprite, this.wallSprite, this.scoring, null, this);
}
私はこのようなwallSprite
を作成していますaddOneRoadSection
を次のように呼んでください:
addRoad: function() {
this.addOneRoadSection(this.xValue, 0);
}
addRoad
はthis.timer
を使用してcreate
に呼び出されています。
これは、scoreCalculator
が10のときに壁を追加することを要約しています。それはうまく動作し、壁はアニメーションがうまくいきますが、衝突の検出はまったく機能しません。
if
のコード内のコードをcreate
関数に移動しようとしましたが、衝突検出でうまく動作します(ただし、他のものが壊れてしまい、そこに保持できません)。私は間違って何をしていますか?私はthis.wallSprite
を毎秒約1回呼び出すので、それは新しいスプライトによって書かれているので、this.wallSprite
として追加されてしまった疑いがありますが、それ以外はどうすればいいのでしょうか?