gpt4 book ai didi

android - 在不同分辨率之间移动时保持同步?

转载 作者:太空狗 更新时间:2023-10-29 15:17:24 24 4
gpt4 key购买 nike

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

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 或更大会怎样?是否产生奇怪的结果?

最佳答案

以上代码有效,只需确保 _oneStep var 是 screenWidth 或 Height(取决于您的对象大小,可能与屏幕相关)。

所以 _oneStep = ScreenWidth/100; Delta 需要添加到任何机芯中。

关于android - 在不同分辨率之间移动时保持同步?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11495198/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com