javascriptでのゲーム制作について。 プログラミング学習の一環として、シューティングゲームを制作しております。 そのゲーム内で、2方向(<の形)に飛んでいく弾を作成していたのですが、思うように動作しません。以下にコードを記します。 fireBullet() { if (!this.doubleBullet) { const bullet = this.bullet.get(); if (bullet) { bullet.enableBody(true, this.ship.x + 30, this.ship.y + 30, true, true); bullet.setTexture('bullet'); bullet.setScale(2); bullet.angle = 0; bullet.setVelocityX(400); } } else { // V字に2連射 const bullet1 = this.bullet.get(); const bullet2 = this.bullet.get(); if (bullet1 && bullet2) { // 右上 bullet1.enableBody(true, this.ship.x + 30, this.ship.y + 30, true, true); bullet1.setTexture('pwrbullet'); bullet1.setScale(2); bullet1.angle = -60 bullet1.setVelocity(400, -680); // 斜め右上 // 右下 bullet2.enableBody(true, this.ship.x + 30, this.ship.y + 30, true, true); bullet2.setTexture('pwrbullet'); bullet2.setScale(2); bullet2.angle = 60 bullet2.setVelocity(400, 680); // 斜め右下 } } } 関数を呼び出す経緯は簡潔に述べさせていただきます。 1、SPACEを押す。 2、update内にて、doubleBulletがtrueとなる。 3、else以下のコードに繋がる。 最初の10行ほど(elseに至るまで)は、Eキーで単発で弾を出す構造となっており、正常に動作しています。 不明な点として、右下に飛ぶ弾(bullet2)は正常に動作するのに対し、右上に飛ぶ弾(bullet1)は動作が不安定です。具体的にいうと、途切れ途切れに発射されてしまいます。 this.bullet = this.physics.add.group({ defaultKey: 'bullet', maxSize: -1, classType: Phaser.Physics.Arcade.Image, runChildUpdate: true }); 上記に記した通り、使用しているbulletのグループで、maxSizeは無制限にしているため、ストックの問題ではなさそうです。
JavaScript