Skip to main content
gamedev.net
🔒 Locked

game speed?

Started by jimothygu 1 reply 350+ views
Original Post
jimothygu
jimothygu
Hey, I have a quick question about game speed and FPS. I''ve been developing a game, and everything is going well - except for the fact that it runs at very different speeds on different computers. For example, my computer is a 1.2ghz with 256ddr ram (and a geforce2mx), and the game runs around ~16 fps, and basically looks like it''s in slow motion. I then decided to run it on my girlfriend''s laptop (1.7ghz 512ram and a mobility radeon 7500) and it ran at what seemed to be normal speed... around 44fps. Then I tried it on my brother''s laptop 2ghz and 256ram and it ran at 110fps, and everything was going WAY too fast . I was just wondering what could be cause of these problems. It''s a pretty simple 2d game, with basic animation - so not really graphic intensive. It makes sense that a faster computer would do things more quickly, but the game speed isn''t supposed to change. Hope someone can help. Thanks!
zealouselixir
zealouselixir
Based on your description, it sounds like you aren''t using time-based motion. In order to make things appear to move at a consistent rate on computers of varying speed, you''ll need a timing mechanism that can calculate what fraction of a second has elapsed since the last frame, then multiply this by the velocity/acceleration/torque/whatever per second to get the delta.

As an example, 2D linear motion:

float timeStep;
...
float velX = 20.0f; // desired speed of object in units/second
float velY = 25.0f;
...
object.X += (velX * timeStep);
object.Y += (velY * timeStep);

where timeStep is a variable you set each frame, according to your timer, that represents the part of a second this frame has taken (e.g. 20 milliseconds is 0.02 seconds; if each frame consistently takes 0.02 seconds, your framerate will be 50 FPS).

In short, you store your velocity as "units per real unit of time" instead of "units applied instantaneously per game tick", leading to something like

velocity = distance/time;
velocity * delta_time = delta_distance;

Later,
ZE.



//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links
[twitter]warrenm[/twitter]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.