The central code loop responsible for handling the running gameplay. At its most basic state, it accepts input, resolves the actions of entities, and renders the scene.

learn more… | top users | synonyms (1)

81
votes
3answers
26k views

Tips for writing the main game loop? [closed]

Can anyone recommend some good tips, articles, sites, etc. for writing the main game loop? What are some things that you should do in the game loop, and what are some things that you shouldn't do in ...
28
votes
3answers
3k views

Several classes need to access the same data, where should the data be declared?

I have a basic 2D tower defense game in C++. Each map is a separate class which inherits from GameState. The map delegates the logic and drawing code to each object in the game and sets data such as ...
23
votes
4answers
2k views

What is the point of “delta” in this code? Does it reflect a standard thing in game dev?

I know very little about game programming but would like to learn more. I am trying to understand the code for this game. I am trying to understand why the code is passing a "delta" to ...
22
votes
2answers
4k views

Is it safe to use Sleep() in game loop (on Windows)?

Is it safe to use Sleep() function on Windows in game loop (C++)? I want to have fixed frame rate.
20
votes
2answers
13k views

A good way to build a game loop in OpenGL

I'm currently beginning to learn OpenGL at school, and I've started making a simple game the other day (on my own, not for school). I'm using freeglut, and am building it in C, so for my game loop I ...
16
votes
3answers
3k views

Is there any harm in having the main game loop run uncontrolled?

I was wondering if there is any possible harm when my game loop runs as fast as the system allows? I currently have a loop, that, by measuring passed time in nanoseconds, runs the game logic and ...
16
votes
4answers
3k views

Should actors in a game be responsible for drawing themselves?

I am very new to game development, but not to programming. I am (again) playing around with a Pong type game using JavaScript's canvas element. I have created a Paddle object which has the following ...
16
votes
9answers
1k views

How do I best remove an entity from my game loop when it is dead?

Ok so I have a big list of all my entities which I loop through and update. In AS3 I can store this as an Array (dynamic length, untyped), a Vector (typed) or a linked list (not native). At the moment ...
16
votes
5answers
964 views

Game actions that take multiple frames to complete

I've never really done much game programming before, pretty straightforward question. Imagine I'm building a Tetris game, with the main loop looking something like this. for every frame handle ...
15
votes
3answers
4k views

Finite state machine in C++

So, I've read a lot about using FSMs to do game state management, things like what an FSM is, and using a stack or set of states for building one. I've gone through all that. But I'm stuck at writing ...
15
votes
2answers
1k views

Where should collision detection logic be placed?

I am developing a small 2D game engine. The characters have a paint method which currently does the following: Calculate the new position of the character as per its speed, etc. Update the collision ...
13
votes
3answers
891 views

Game loop, how to check for conditions once, do something, then not do it again

For example, I have a Game class and it keeps an int that tracks the player's lives. I have a conditional if ( mLives < 1 ) { // Do some work. } However this condition keeps firing and the ...
13
votes
2answers
3k views

What is the standard C# / Windows Forms game loop?

When writing a game in C# that uses plain-old Windows Forms and some graphics API wrapper like SlimDX or OpenTK, how should the main game loop be structured? A canonical Windows Forms application has ...
13
votes
2answers
1k views

Design of a turn-based game where actions have side-effects

I am writing a computer version of the game Dominion. It is a turn-based card game where action cards, treasure cards, and victory point cards are accumulated into a player's personal deck. I have the ...
12
votes
2answers
2k views

“Optimal” game loop for 2D side-scroller

Is it possible to describe an "optimal" (in terms of performance) layout for a 2D side-scroller's game loop? In this context the "game loop" takes user input, updates the states of game objects and ...
12
votes
4answers
2k views

Programming the combat sequence in a role playing game

I'm trying to write a short "game" where a player goes around and fights monsters but I have no idea how to handle the combat. For example, say I have a "Warrior" and a "Troll". How do the two fight ...
12
votes
1answer
697 views

Behavior Trees :: Actions That Take Longer Than One Tick

From what I understand on Behavior Trees, each Behavior should be a short goal oriented Action that could be done in a few iterations. So for example, below is an image of a Behavior Tree: Now let ...
11
votes
2answers
5k views

how should i develop my android game efficiently?

I have attached a image of a flow chart that i made in paint. The image shows how i want to develop my game. I want a game that runs great with smart coding that is easy to update and ad features ...
11
votes
2answers
4k views

Semi-fixed or Fully-fixed timestep?

I am making an iphone shmup and am trying to decide what type of game loop to use. I want to use either semi-fixed timestep or fully-fixed timestep. With semi-fixed timestep I will make zero or more ...
10
votes
3answers
1k views

EXTREMELY Confused Over “Constant Game Speed Maximum FPS” Game Loop

I recently read this article on Game Loops: http://www.koonsolo.com/news/dewitters-gameloop/ And the recommended last implementation is confusing me deeply. I don't understand how it works, and it ...
10
votes
4answers
1k views

Using idle time in turn-based (RPG) games for updating

If you take any turn based RPG game there will be large periods of time when nothing is happening because the game is looping over 'wait_for_player_input'. Naturally it seems sensible to use this time ...
8
votes
2answers
2k views

Java 2D game programming: Different approaches to make a game loop

I am new to Java game programming, but the more I read the more I'm confused, because I've seen several different approaches to make a game loop: 1. The standard approach, that uses the Timer class ...
7
votes
3answers
2k views

Is a separate thread for game loop compulsory for simple games?

I am new to game development. In order to learn I am recreating this game on android platform. You can observe the game-play video at the above link. It is a simple game. I have read a lot of ...
7
votes
4answers
600 views

Simultaneous game states

I think I understand the basic idea behind a Finite State Machine-based game loop. But I'm trying to write a little game in which the same object can simultaneously be in multiple, independent states. ...
7
votes
2answers
3k views

Server side game loop

Many java games use thread.sleep() to controll fps. Since the server does not display graphics, should the server game loop keep running just calculating delta time? Like this example: long ...
7
votes
2answers
2k views

Multi threaded game - updating, rendering, and how to split them

From the StackOverflow post (it was recommended I move this): So, I'm working on a game engine, and I've made pretty good progress. However, my engine is single-threaded, and the advantages of ...
7
votes
2answers
1k views

Managing game state / 'what to update' within an XNA game 'screen'

I'm trying to figure out how best to manage state within my game screens - please bare with me though! At the moment I'm using a heavily modified version of the fantastic game state management example ...
7
votes
2answers
589 views

Replay system: record inputs or events?

I read this: How to design a replay system But it don't really answer my question. My game is built with the client "view" of the game as a separate program from the server "model" and "controller". ...
6
votes
3answers
1k views

What are “frame rate” and “fps?”

Can someone give me a detailed explanation about frame rate and fps concepts?
6
votes
3answers
7k views

XNA game loop Update and Draw

I'm confused on how the game's methods are called and when. So I read that the sequence is: Initialize LoadContent Update Draw UnloadContent Where 3 and 4 are the game loop, so after Update is ...
6
votes
1answer
2k views

How to chain actions/animations together and delay their execution?

I'm trying to build a simple game with a number of screens - 'TitleScreen', 'LoadingScreen', 'PlayScreen', 'HighScoreScreen' - each of which has it's own draw & update logic methods, sprites, ...
6
votes
1answer
658 views

When to detect collisions in game loop

My game loop uses a fixed time step to do "physics" updates, say every 20 ms. In here I move objects. I draw frames as frequently as possible. I work out a value between 0 and 1 to represent the ...
6
votes
1answer
708 views

Android game loop's effect on cpu/battery usage - unexpected results

I will try to keep this question as concise and as readable as I can. I recently came across an odd problem with my Android game that I'm developing. It's an openGL ES 2.0 game and initially I was ...
5
votes
2answers
728 views

Why is my gameloop logic not being restricted to 60 per second?

Here is my gameloop (taken from http://www.koonsolo.com/news/dewitters-gameloop/) which is supposed to limit the game (logic) updates to 60 per seconds and render as fast as the device allows: long ...
5
votes
2answers
470 views

Physics in my game confused after restructuring the Game loop

I'm on my way with making a game in Java. Now I have some trouble with an interpolation based game loop in my calculations. Before I used that system the calculation of a falling object was like ...
5
votes
2answers
3k views

How should I structure my menu / game loop?

I'm trying to decide on how to structure my main game loop - every example I've seen of the game loop looks a bit like this: while (true) { UpdateGame(); DrawGame(); } i.e. it ignores the ...
5
votes
1answer
127 views

Is there a good alternative to a world state data structure?

How do you avoid one big data structure containing all the current world state ? Let's pretend we're in a real-time strategy game, how would you code a skill that decrease mana of units around it ? ...
5
votes
2answers
337 views

Draw and update order in 3d graphics

In all of the code samples that I have looked at, the game loop looks something like this: while(true) { InputAndUpdate(); Draw(); SwapBuffers(); } However doesn't this destroy ...
5
votes
2answers
242 views

Simultaneous events in a realtime system, where processing order causes different outcomes

I am working on a realtime dungeon crawler, focusing on a relatively complex and flexible skill system. Somewhat similar to MMORPGs with many compound spells, area effects, buffs/debuffs, ect. I am ...
5
votes
2answers
1k views

Correct order of operations in a platformer game loop

I've run into an issue with my Mega Man engine, and the structure of my game loop is making it very difficult to fix. With Rush Jet, or any falling platform, Mega Man needs to stay attached to the ...
4
votes
5answers
362 views

Game Loop Problem - Growth and Recharge as Integer Values

I have a question about game loops. I understand that you shouldn't have a static loop, say 100ms and set something's speed to 1px/frame so it moves 10px/sec. You should have a speed and multiple that ...
4
votes
3answers
508 views

Best practices on separating Update and Draw on game loop

I've been working on my first HTML5 prototype and I found a good model that uses the regular Update and Draw loop we see in game dev. My question is, where does one end and the other begins? The ...
4
votes
2answers
1k views

Why does my turn-based game loop allow the enemy to act repeatedly?

I'm trying to create a turn-based game in pyGame but hit a wall when trying to properly handle the main game loop. So I have something like this: def loop(self): while self.stategame==1: ...
4
votes
3answers
598 views

How do I do a game loop in c99?

I'm having trouble with how to structure a game using c99. I've seen a few tutorials on making a game loop, but they are all done with c++ and classes. My main problem seems to be moving data around ...
4
votes
2answers
4k views

Constant game speed independent of variable FPS in OpenGL with GLUT?

I've been reading Koen Witters detailed article about different game loop solutions but I'm having some problems implementing the last one with GLUT, which is the recommended one. After reading a ...
4
votes
4answers
1k views

Creating the concept of Time

So I've reached the point in my exploration of gaming where I'd like to impliment the concept of time into my little demo I've been building. What are some common methodologies for creating the ...
4
votes
4answers
20k views

Android game scrolling background

I'm just trying to figure out the best approach for running a scolling background on an android device. The method I have so far.... its pretty laggy. I use threads, which I believe is not the best ...
4
votes
3answers
2k views

Game loop on windows

I have seen different "basic" game loops both from books like "Introduction to 3D game programming with DX11" or online tutorial ( Rastertek ) and if we take off all the fancy stuff to control ...
4
votes
4answers
1k views

C++ Game engine time scale

i have begun creating a very simple game engine and i am trying to work out how to create a time scale for the game.by time scale i mean some way of increasing and decreasing the speed of the game(not ...
4
votes
2answers
217 views

JS: Should I have an upper limit to the number of update cycles per sec?

I'm making a javascript game engine for fun and one thing I noticed was that my laptop runs super hot with the simplest game mechanics and that my game is doing about 600 updates per second. The ...