私は最近 Codecademy で JavaScript の学習を始めました。知識を広げるため、また楽しみのために、Gyrostorm による HTML5 ゲーム チュートリアル ( http://www.youtube.com/playlist?list=PL290A4D2398C97186/ ) に従いました。
これで、彼のゲームの私のバージョンを作成するためのチュートリアルが完了しましたが、スペースバーを押したままにすると、弾丸が特定の速度で発射されるようにしたいと考えています。現在、発射するにはスペースバーを押し続ける必要があります。私は Jet.shoot 関数と Jet.checkShoot 関数を持っていますが、何度も setIntervals と setTimeouts を試みた後、何も機能しません! 助けてください!
Jet.prototype.checkShooting = function() {
if(this.isSpacebar && !this.isShooting) {
this.isShooting = true;
this.bullets[this.currentBullet].fire(this.noseX, this.noseY)
this.currentBullet++;
if(this.currentBullet >= this.bullets.length) {
this.currentBullet = 0;
}
} else if(!this.isSpacebar) {
this.isShooting = false;
}
};
Jet.prototype.shoot = function() {
this.isShooting = true;
this.bullets[this.currentBullet].fire(this.noseX, this.noseY);
this.currentBullet++;
if(this.currentBullet >= this.bullets.length) {
this.currentBullet = 0;
}
}
これは私がこれまでに持っているもののライブバージョンです: https://googledrive.com/host/0B2Xb6VzofFX-OGxEcnV3OUNTdFU/index.html
ありがとう!