Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript前后移动对象_Typescript_Object_Position - Fatal编程技术网

Typescript前后移动对象

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;

我正在做一个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;
            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;从内部移动功能