我最近开始使用 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
谢谢!