Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [game-loop]

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.

Filter by
Sorted by
Tagged with
271 votes
11 answers
112k views

When should I use a fixed or variable time step?

Should a game loop be based on fixed or variable time steps? Is one always superior, or does the right choice vary by game? Variable time step Physics updates are passed a "time elapsed since last ...
Nick Sonneveld's user avatar
137 votes
1 answer
99k views

What should a main game loop do?

Generally, what are the core things that one should do in the game loop, and what are some things that one shouldn't do in the game loop?
86 votes
5 answers
23k views

What is the point of update independent rendering in a game loop?

There are dozens of articles, books and discussions out there on game loops. However, I pretty often come across something like this: ...
Sam's user avatar
  • 833
43 votes
5 answers
11k 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 <...
alex's user avatar
  • 763
40 votes
3 answers
35k 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 ...
user avatar
39 votes
3 answers
25k views

When 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 ...
Juicy's user avatar
  • 581
34 votes
2 answers
38k 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 ...
Jeff's user avatar
  • 2,448
29 votes
2 answers
14k 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.
hemogoblin's user avatar
24 votes
4 answers
3k 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 Shipcontrols.js,...
bernie2436's user avatar
20 votes
4 answers
8k 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 ...
dot_Sp0T's user avatar
  • 2,032
20 votes
5 answers
2k 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. ...
user avatar
20 votes
2 answers
7k 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 ...
Cracker's user avatar
  • 497
19 votes
1 answer
5k 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 ...
Free Lancer's user avatar
  • 1,283
18 votes
2 answers
6k views

Why does my sprite player move faster when I move the mouse?

I'm trying to develop a simple game made with Pygame (Python library). I have a sprite object which's the player and I move it ...
Drumnbass's user avatar
  • 295
17 votes
3 answers
6k views

Game loop isn't performing well enough, so my frame rate is too low (Windows Form + GDI+)

I decided to learn about building games, so I picked up C# to use it along with Windows Form - I already have C# experience, so that was the main reason I did so. That said, I tasked myself to build a ...
curiousguy_08's user avatar
17 votes
3 answers
7k views

Fixed timestep game loop, why interpolation

This is a very standard way of doing a fixed timestep game loop, where you just accumulate time from the previous frame and consume it in discrete steps with the physics engine: ...
Gavriil's user avatar
  • 183
17 votes
9 answers
5k 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 ...
Iain's user avatar
  • 6,528
16 votes
3 answers
8k 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 ...
Electro's user avatar
  • 465
15 votes
2 answers
12k 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 ...
Ryan's user avatar
  • 887
14 votes
2 answers
4k 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 ...
MrDatabase's user avatar
  • 1,951
13 votes
3 answers
3k 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 ...
EddieV223's user avatar
  • 427
13 votes
3 answers
5k 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 ...
tsujp's user avatar
  • 239
13 votes
4 answers
7k 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 ...
Harv's user avatar
  • 131
12 votes
2 answers
3k views

Pausing the game inside the game loop

Inside the game loop, the game is paused by pressing P, meaning that the game loop does not run anymore. Problem is that after this loop is halted, P cannot be pressed again to resume the loop, since ...
GSquadron's user avatar
  • 307
11 votes
2 answers
3k views

Which of these two codes are 'better'? Making a local variable or a class variable?

Im making more games and asking more stupid questions. Hopefully this one is very brief. I'm making a very basic class which just moves a Player object by applying force to a rigidbody, but it got me ...
Big T Larrity's user avatar
11 votes
3 answers
6k views

UPS and FPS - What should I limit and why?

I'm currently writing a game using C++ and SDL2 and there's one thing that I'm wondering about - does it make sense to limit my frames per second (FPS) and/or my updates per second (UPS)? I get the ...
DocCoock's user avatar
  • 113
11 votes
1 answer
7k views

CPU usage, game loop and sleep()

I've read about this topic on numerous discussion sites, but I can't seem to find a clear definitive (up-to-date) answer, and hopefully this will me some more insight: I've read the excellent game ...
KaiserJohaan's user avatar
  • 1,464
10 votes
2 answers
21k views

What's the difference between Update and FixedUpdate in Unity, and should I bother?

I was told to use Update() for graphics and FixedUpdate() for physics, but sometimes my inputs won't register when I use ...
Tokamocha's user avatar
  • 427
10 votes
5 answers
19k 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 ...
Edoardo Dominici's user avatar
10 votes
4 answers
5k 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 ...
jin's user avatar
  • 101
10 votes
2 answers
6k 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 (...
user1812379's user avatar
9 votes
3 answers
10k views

OpenGL - How come drawing sprites takes so much performance

I'm wondering how drawing simple geometry with textures can eat up so much performance (below 60fps)? Even my good graphics card (GTX 960) can "only" draw up to 1000 sprites smoothly. The textures I'm ...
mrdlink's user avatar
  • 323
9 votes
4 answers
2k 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 ...
PrettyPrincessKitty FS's user avatar
9 votes
2 answers
2k 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". (...
Klaim's user avatar
  • 2,624
8 votes
2 answers
6k 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: ...
Wolfrevo Kcats's user avatar
8 votes
2 answers
5k 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 ...
CodeBunny's user avatar
  • 205
7 votes
3 answers
3k views

What are "frame rate" and "fps?"

Can someone give me a detailed explanation about frame rate and fps concepts?
xdevel2000's user avatar
7 votes
1 answer
1k views

How can City-sim simulate hundreds of characters?

My games usually start lagging quite easily when there are a couple hundred of boxes representing possible characters. While games like SimCity or even Anno have hundreds of characters. I realized ...
MisteriosM's user avatar
7 votes
3 answers
28k views

How can I implement a main menu?

I have been following the tutorials at http://lazyfoo.net/tutorials/SDL/index.php and although they are all very well written and I have learned more than I would have on my own, I am not sure how to ...
Elias's user avatar
  • 173
7 votes
3 answers
14k 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 ...
xdevel2000's user avatar
7 votes
1 answer
13k views

Game Update in Libgdx

In libgdx, the game loop is the render() method. But why is that, and is there a way where I can make an update() method that is called 60 times a second? As in the update() method, I would add the ...
user43353's user avatar
7 votes
2 answers
465 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(); } ...
Hannesh's user avatar
  • 981
7 votes
1 answer
2k views

In JavaScript, should I write a game loop for a turn-based game?

I am using javascript and HTML5 canvas for turn-based games (e.g., checkers, mastermind, minesweeper). Should I write a fixed-timestep game loop? What are the alternatives?
userx01's user avatar
  • 346
7 votes
2 answers
525 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 ...
Szoltomi's user avatar
7 votes
1 answer
356 views

How to execute game logic every 100ms but render as fast as possible?

I have created a simple snake clone and would like to execute game logic every 100ms while rendering as fast as possible. How can I achieve this when the program might run with very different frame ...
ooxi's user avatar
  • 224
7 votes
2 answers
2k 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 ...
Tesserex's user avatar
  • 2,294
6 votes
3 answers
258 views

How and when should I update events occuring after a while?

This question is not language specific but a more generic approach on how to deal with lazy updates for some game variables. Let's say, for instance, that I want to implement a "character age system" ...
J. Doe's user avatar
  • 63
6 votes
4 answers
2k 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. ...
Kristian D'Amato's user avatar
6 votes
1 answer
3k views

Pro's/Con's of separating game logic and render threads

Originally, I have thought that it is good practice to separate my game logic (updating) from my rendering thread. In this threading model, the rendering thread has no limitation on frame rate and ...
Nicholas Miller's user avatar
6 votes
1 answer
4k 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, ...
codinghands's user avatar

1
2 3 4 5
10