Skip to content Skip to sidebar Skip to footer

Game Speed On Different Devices Isn't Same

I have an app, in which I have constant int speed = 5; On each update, the game object (player) is moving 5px ahead. Problem is, that I can't handle that on different devices - old

Solution 1:

The way you are addressing the issue is not the best one, for instance, android can run on many many different types of devices, all of them with different screen sizes, that is the reason why you have to consider how many frames per second is your game rendered, this value is not a constant and can vary depending on devices, processes running etc... with this information and the screen_width you can accurately calculate how many pixels per second an image must be moved in order to generate the same speed effect independent from screen sizes... Many game frameworks like libgdx can retrieve this information (the name it "delta" as a time diff. between 2 consecutive frames). Lets break it down with an example: Consider the tablet in the image below, your game needs to translate the blue dot, form the left to the right in exactly one second. So the solution to this is completly dependent from the table size and the tablet capabilities.

If you have a Tablet with hypothetically 100 as a width and rendering a 10 Frames per Second, this means your onDraw Method will be called 10 times per second, so the blue dot can be increase its position in a rate of 10 pixels per rendered frame in order to be translated from the left to the rigth in 1 second, if the delta changes, no matter why, then the speed will be the same.

enter image description here

Now I hope with this information you can get what you need to develop your game.


Post a Comment for "Game Speed On Different Devices Isn't Same"