Typescript前后移动对象
我正在做一个typescript网络游戏 我需要对象沿Y轴前后移动。 基本上,物体从库里开始,速度为dy,它的当前坐标是Y 当电流Y小于coorY 10时,它向右移动;当电流Y大于coorY+50 60时,它向左移动Typescript前后移动对象,typescript,object,position,Typescript,Object,Position,我正在做一个typescript网络游戏 我需要对象沿Y轴前后移动。 基本上,物体从库里开始,速度为dy,它的当前坐标是Y 当电流Y小于coorY 10时,它向右移动;当电流Y大于coorY+50 60时,它向左移动 public Move(): void { this._dy = 1; this.dir = true; if (this.y > this.coorY + 50) { this.dir = true;
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;
}
}
但不知何故,物体移动得很小,看起来像是在摇晃,或者只是停留在原来的位置。如何使其前后移动?删除此项。dir=true;从内部移动功能