3

我的问题是让一个项目以相同的速度和时间在不同的屏幕上移动。目前该项目没有移动或快速移动。我为要到达的项目指定两个点和最大速度。

Var _oneStep 是我尝试同步分辨率。

//Get a fraction of screen size?
_oneStep = ScreenWidth / 100;

//Delta being last update time.
public void MoveItem(double Delta)
{
    //Keep at Max speed.
    if(Math.abs(_xVelocity)  > _maxSpeed || Math.abs(_yVelocity)  > _maxSpeed)
    {
        _accelerationSpeed = 0.0001f * (_maxSpeed / _oneStep);
    }
    //Or Speed up.
    else
    {
        _accelerationSpeed = 0.00030f * (_maxSpeed / _oneStep);
    }
    //Destination is above 10% distance or below speed up or down

    _xVelocity += _accelerationSpeed * Math.cos(Math.toRadians(_degrees));
    _yVelocity += _accelerationSpeed * Math.sin(Math.toRadians(_degrees));

    _currentPosition.x += (((_xVelocity * _accelerationSpeed) + _oneStep) * Delta);
    _currentPosition.y += (((_yVelocity * _accelerationSpeed) + _oneStep) * Delta);

    CheckAtDestination();
}

一些数字:

System.out.println("X: "+ _xVelocity + " Y: " + _yVelocity); = X: 1.0018943990787657 Y: 1.0109980390961948
System.out.println("XPos: "+ _currentPosition.x + " YPos: " + _currentPosition.x); = XPos: 36 YPos: 36
System.out.println("Degrees: " + _degrees); = Degrees: 80.22677351282063
System.out.println(Delta); = 0.3309303333093033

如果 Delta 变为 1 或更大会怎样?是否产生了奇怪的结果?

4

1 回答 1

0

上面的代码有效,只需确保 _oneStep 变量是 screenWidth 或 Height (取决于您的对象大小,可能取决于屏幕)。

所以 _oneStep = ScreenWidth / 100; 并且需要将三角洲添加到任何运动中。

于 2012-07-27T14:39:32.500 回答