Game Speed

Started by
3 comments, last by Modena_au 21 years, 1 month ago
Ok, I''m programming my 2nd game. The first was a simple break out style game. This time I''m making a nibbles clone. All is going great. My coding seems to be getting much more organized and straight forward. But Something occured to me, that I didn''t have to deal with in the last game. The speed was directly calibrated to my machine. What I want to do this time, is to write my game so that it plays the same speed (relativly) on different machines. What are some popular ways to implement this? What I''m planning to do is to call my update function every x number of milliseconds, but I was wondering if this is the best way to do it. Thanks in advance
Advertisement
The way you mentioned may be fine for a simple game like nibbles, but for better results you might want to try frame-rate independent motion. Basically you calculate the amount of time that has passed during the frame, and then you update everything accordingly. For example, say I wanted an object to move 100 pixels every second. that would be .1 pixels every millisecond. Once I''ve calculated how many milliseconds have passed for the current frame, I multiply the number of milliseconds that have passed by the amount I want to move the object (.1 pixels).
-YoshiXGXCX ''99
Ok, excellent. I understand what your saying. I don''t think that will be too much work to implement for a project of this size either. Thanks alot for your suggestion.
quote:Original post by Modena_au
Ok, excellent. I understand what your saying. I don''t think that will be too much work to implement for a project of this size either. Thanks alot for your suggestion.

What I''ve done is something like the following. Just make sure that everything that draws can be Updated(). You can either do it this way, or have the Draw() method take the elapsed time in seconds. You''ll have to keep track of the objects velicity/direction and have it move just as much as you want it to over time.
class CBaseObject  {public:	CBaseObject(){}	virtual ~CBaseObject(){}	virtual bool	Update(const double& rElapsedSeconds)= 0;	virtual bool	Draw()=0;protected:private:}; 

You''re also going to need some sort of timer:
class wxTimer{public:	wxTimer();	virtual ~wxTimer();	virtual double GetElapsedSeconds();protected:...private:}; 

That you can then poll for elapsed time, and pass that to everything that is drawing.

- sighuh?
- sighuh?
If you''re doing a block-based movement you might find these options a little confusing unless you store position as a float and round it each frame. For a game so simple you could set up a windows timer or your own which runs the game at say 30fps. Though this is bad for a bigger game where you can''t guarantee the fps for something so computationally limited it might be simpler - a nice example of an interrupt driven program.


Read about my game, project #1
NEW (18th December)2 new screenshots, one from the engine and one from the level editor


John 3:16

This topic is closed to new replies.

Advertisement