你能解释一下 moveUp() 是如何工作的吗?

Can you explain how is moveUp() is working?

我是新手。当我练习创建 Class interface Moveable, MoveablePoint.

我在互联网上搜索了这段代码,但我不明白为什么 moveUp() 是 y=y-yspeed。你能给我解释一下什么是 yspeed(它是速度或矢量)以及为什么 y=y-yspeed.I 非常感谢你的回答

 public class MovablePoint implements Movable{

    public int x, y, xSpeed, ySpeed;

    public MovablePoint(int x, int y, int xSpeed, int ySpeed) {
        this.x = x;
        this.y = y;
        this.xSpeed = xSpeed;
        this.ySpeed = ySpeed;
    }


    @Override
    public void moveUp() {
        y -= ySpeed;
    }

    @Override
    public void moveDown() {
        y += ySpeed;
    }

    @Override
    public void moveRight() {
        x += xSpeed;
    }

    @Override
    public void moveLeft() {
        x -= xSpeed;
    }
}

Can you explain to me what is yspeed (it's velocity or vector)

速度就是“某物移动的速度”。例如,就像您开车时的汽车速度可能是 35 英里/小时或 60 公里/小时。这意味着汽车每小时行驶 35 英里的距离。

它与速度有关但不相同(google)。

在您的示例中,“yspeed”似乎是 MoveablePoint 的 y 属性 值变化的速率。

and why y=y-yspeed.I really appreciate your answer

同样,由于速度是物体移动的速度,这意味着 y 将在一段时间内移动 yspeed 个单位,这意味着它需要通过 [=12] 进行调整=] 该时间间隔内的金额。同样,考虑一辆从 0 英里标记开始并以 35mph 的速度行驶的汽车,它将在 1 小时后到达 35 英里标记。换句话说,它的位置 y 将是它的原始位置 + 它移动的速度 (y + mph)。

在这种情况下,它是 negative (y - yspeed) 因为在屏幕坐标中“向上”移动实际上意味着减少 y 位置,因为屏幕坐标从左上角开始.当 y = 0 时,您位于屏幕顶部,当您增加 y 时,您将向下移动屏幕。