キャンバスと JavaScript を使用して、横スクロールのエンドレス スペースをテーマにしたゲームを作成しています。上下の矢印を使用するだけで宇宙船を制御しています。キーを離したときに船が停止しないように、ある種の動きの緩和を実装したいと考えています。私は周りを見回しましたが、何も見つかりませんでした。さらに、自分の試みが機能していません。これは私が試したものです。
Jet.prototype.checkDirection = function () {
if (this.isUpKey) {
this.drawY -= this.speed;
if (this.speed < 5) {
this.speed += 0.1;
}
}
if (this.isDownKey) {
this.drawY += this.speed;
if (this.speed < 5) {
this.speed += 0.1;
}
}
if (!this.isUpKey) {
if (!this.isDownKey) {
if (this.speed >= 0) {
this.drawY -= this.speed;
this.speed -= 1;
}
}
}
if (!this.isDownKey) {
if (!this.isUpKey) {
if (this.speed >= 0) {
this.drawY += this.speed;
this.speed -= 1;
}
}
}