0

I have a top down shooter using the paint method and I would like for it to work on all displays. It works by getting the resolution and dividing the x and y by 40 to separate it all up into squares. My method of making the bullets move is by having a thread and a move method.

public void move(){
x += dx;
y += dy;
}

But if the persons computer is smaller, the bullet would move across the screen quicker. How can I get it to move at slower on smaller screens and faster on bigger screens? Thank you for any suggestions.

4

2 回答 2

0

我认为您忘记了并非每台计算机都以相同的速度运行,如果您的循环速度尽可能快,那么它在每台计算机上的运行速度都会大不相同。我建议实现增量缩放,这包括对最后一帧进行计时,比如你想要 60fps,这意味着它需要 16 毫秒,所以花点时间把它分开,例如:

int lastframe = getFrameTime();
float scaler = lastFrame/(1000f/targetFrameRate)

然后将所有动作乘以这个比例。如:

public void move() {
    x += dx * scaler;
    y += dy * scaler;
}

还可以看到不同屏幕尺寸更快是什么意思,这是因为像素密度,要获得这一点,您必须获得屏幕物理尺寸以及分辨率。例如,如果您的屏幕是 20 毫米宽,它的 1280x720,它是 20/1280 ,这让您知道每个像素都是 0.015 毫米宽。然后,您可以使用上述标量技术来缩放它们以移动物理世界速度。

于 2013-09-09T20:23:18.067 回答
0

你说的慢是什么意思?你的意思是子弹在屏幕上移动的总时间(以秒为单位)在不同的设备上是不同的吗?

假设您按照您的描述正确进行了所有计算,我认为您忘记了一个因素:不同的设备具有不同的计算速度(也可能是屏幕更新速度),因此一个设备中的“滴答声”可能比其他设备长或短. 所以当你调用 move 时,你应该计算从上次调用moved() 到现在已经过去了多少时间,然后你会根据它计算出dx 和dy。希望这是有道理的

于 2013-09-09T20:10:30.470 回答