#### Archived

This topic is now archived and is closed to further replies.

# Game loop structure

This topic is 6652 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi Everyone! I''m a graduate computer science student and have some programming skills with C, C++ and Java. Recently I''ve got interested in game programming, but I''ve never programmed any real-time interactive application like a game, so I have some questions about it and guessed you could help me: How do I control the speed of a game? I mean not changing the gameplay speed, regardless of the power of the machine it''s running on (not playing in "slow-motion" on a slow machine). Does game programming need any use of threads? Thanks, lchavier

##### Share on other sites
There are two major ways to deal with time.

1) You could lock the frame rate at a minimum, say 25 or 30 fps.

2) You could put in all your velocities as fractions (pixels per millisecond) and use a timer to keep the time difference from one frame to the next, and multiply all motion by the time. This is the best, IMHO, because it will run more smoothly on faster computers, but still run at the correct speed on slower ones.

And yes, threads are used sometimes.

##### Share on other sites
Regarding the second approach, instead of expressing velocities as pixels per millisecond you might instead express it in terms of world units per a certain interval of time. Using world units allows for a dynamic relationship between space (actual object size) and pixels. Using time intervals larger than milliseconds allows you to more conveniently express slower velocities.

##### Share on other sites
Regarding the second approach, instead of expressing velocities as pixels per millisecond you might instead express it in terms of world units per a certain interval of time. Using world units allows for a dynamic relationship between space (actual object size) and pixels. Using time intervals larger than milliseconds allows you to more conveniently express slower velocities.

##### Share on other sites
Regarding the second approach, instead of expressing velocities as pixels per millisecond you might instead express it in terms of world units per a certain interval of time. Using world units allows for a dynamic relationship between space (actual object size) and pixels. Using time intervals larger than milliseconds allows you to more conveniently express slower velocities.

##### Share on other sites
Regarding the second approach, instead of expressing velocities as pixels per millisecond you might instead express it in terms of world units per a certain interval of time. Using world units allows for a dynamic relationship between space (actual object size) and pixels. Using time intervals larger than milliseconds allows you to more conveniently express slower velocities.

##### Share on other sites
Regarding the second approach, instead of expressing velocities as pixels per millisecond you might instead express it in terms of world units per a certain interval of time. Using world units allows for a dynamic relationship between space (actual object size) and pixels. Using time intervals larger than milliseconds allows you to more conveniently express slower velocities.

##### Share on other sites
Damn it! Happy trigger finger of mine. I''m sorry for the quintuplicate post. It was unintentional (server looked like it wasn''t responding so I used the stop button, four times too many).

1. 1
Rutin
34
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
633331
• Total Posts
3011398
• ### Who's Online (See full list)

There are no registered users currently online

×