我正在制作打字稿网页游戏。
所以基本上,对象从 coorY 开始,速度为 dy ,其当前坐标为 Y 。
当前 Y 小于 coorY (10)时,当它大于 coorY 时,它向右移动 50 (60),向左移动。
public Move(): void {
this._dy = 1;
this.dir = true;
if (this.y > this.coorY + 50) {
this.dir = true;
console.log("Forth " + (this.y - this.coorY));
}
else if (this.y < this.coorY) {
this.dir = false;
console.log("Back " + (this.y - this.coorY));
}
if (this.dir) {
this.y -= this._dy;
}
else if (!this.dir) {
this.y += this._dy;
}
}
但不知何故,物体移动很少,看起来像是在颤抖,或者只是停留在原来的位置。如何让它来回移动?