Skip to main content

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
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
137 votes
1 answer
100k 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?
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
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
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
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
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
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
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
3 votes
2 answers
3k views

Using an interpolated game loop (such as Gaffer's final game loop), will the frame be rendered out of sync?

A highly recommended game loop is one from an article called Fix Your Timestep. It presents a method to update using a semi-fixed time step with interpolated rendering. The problem with this is that, ...
Dan Grower's user avatar
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
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
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
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
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
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
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
4 votes
1 answer
6k views

Implement an upper FPS limit in the gameloop

I implemented my game-loop as described in deWiTTER's article, using the last approach with an unlimited FPS and a constant game-speed. My problem is, that the unlimited FPS cranks up my CPU usage to ...
Lukas Knuth's user avatar
1 vote
2 answers
845 views

Updating entities in response to collisions - should this be in the collision-detection class or in the entity-updater class?

In a game I'm working on, there's a class responsible for collision detection. It's method detectCollisions(List<Entity> entities) is called from the main ...
Aviv Cohn's user avatar
  • 913
0 votes
2 answers
1k views

How to detect collision between two directed object?

I'm currently writing a game which is like Battle City game. But right now I'm facing a trouble involved to checking collision between two objects. This is the code that I wrote: ...
Giang TT's user avatar
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
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
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
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
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
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
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
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
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
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
5 votes
2 answers
2k views

Fixed timestep with interpolation & rounding draw positions: jerky animation when the character is not moving

I've implemented a deterministic, fixed timestep system from here: http://gafferongames.com/game-physics/fix-your-timestep/ Everything works fine, output is the same with each step but there's one ...
Jacob's user avatar
  • 2,552
4 votes
1 answer
11k views

Java Game Loop Efficiency

I was watching 2 video tutorials on how to make java game and read a couple articles about game loop. However, I'm still confused about how game loop actually works. The first tutorial used code that ...
Zerro97's user avatar
  • 53
4 votes
3 answers
2k 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 ...
Galvas's user avatar
  • 113
4 votes
2 answers
872 views

C++ Object management/deletion

I am working on a game with a lot of bullets, currently every second it loops through a vector of bullet objects and checks if its marked for erasure or not. ...
Sam Boman's user avatar
4 votes
1 answer
2k views

does order of updates and renders matter?

I know in a game loop there needs to be an order like physics should update before rendering. So, I have created two separate functions: update and render and the game loops like below: ...
Gasim's user avatar
  • 199
3 votes
2 answers
4k views

Can I always assume that fixed time step in Unity is reliable?

I was thinking about games on low end machines or phones where the CPU would be limited. If I were to move all of my game logic into FixedUpdate() can I assume that ...
user3797758's user avatar
  • 3,641
3 votes
2 answers
8k views

Turn-based Strategy Loop

I'm working on a strategy game. It's turn-based and card-based (think Dominion-style), done in a client, with eventual AI in the works. I've already implemented almost all of the game logic (methods ...
Djentleman's user avatar
3 votes
2 answers
1k views

How can I fix my velocity damping to work with any delta/frame time?

I am decreasing my velocity by 50% every second using a guide I found online. I am using the code here and it gives the right result but only for very small values for dt: ...
user avatar
3 votes
3 answers
2k views

How precise should timers in update loops be?

What is the suggestion of "enough precision" in a timer for a fixed game update loop? Currently I'm testing with this code, but it sometimes misses 1-2 updates @ 50hz. While at 30hz it seems to work ...
hayer's user avatar
  • 596
2 votes
5 answers
6k views

How to make the game run at 60 FPS in Irrlicht?

I want my game run at 60 fps, but I don't know where to start, I have the simple loop: while(device->run()){ How do I lock the frame rate to 60 FPS?
fracedo's user avatar
  • 61
2 votes
1 answer
4k views

Should game logic update per second or per frame?

I'm trying to wrap my head around how and when to update an entities position. My game loop updates logic at 25 FPS and renders at 50-60 (Depending on the computer hardware). So lets say I'm moving ...
Matt's user avatar
  • 191
2 votes
2 answers
684 views

Questions About Game Loops

I've been reading up how to lay out a game loop that'll work optimally in both great and not so great conditions but I think I've confused a few techniques together... so I have some questions... ...
NovaCrist's user avatar
  • 383
2 votes
1 answer
1k views

javascript game loop and game update design

There is a main game loop in my program, which calls game update every frame. However, to make better animation and better control, there is a need to implement a function like ...
zuo's user avatar
  • 123
2 votes
4 answers
2k views

Android Game-Loop (rendering & logic removed, but still 'skipping frames')

Overview Guys really hoping for some help here. My game loop is based on code from Fix Your Timestep!. I've read the article more than a few times, but I can't quite work out what exactly is ...
BungleBonce's user avatar
  • 1,927
2 votes
1 answer
429 views

Client and server loops don't match up

I'm trying to build a small networked game using WebGL and NodeJS. I have a basic client and server setup and I'm at the point where I'm trying to implement dead reckoning to simulate what happens on ...
user1157885's user avatar
1 vote
2 answers
105 views

Updating bots/AI behavior after a fixed elapsed timestamp in game loop?

I am developing a HTML5 game in javascript. Now I have created a few bots and they should be able to change their orientation after a few seconds/a fixed timestamp in the game loop. Suppose my game ...
newguy's user avatar
  • 255
0 votes
1 answer
2k views

In some games, we just let the main() loop be the Player object or Table object?

I was thinking that let's say if there is a game of Blackjack or MasterMind, then we should have a class called Dealer or ...
nonopolarity's user avatar
0 votes
3 answers
5k views

C++ GameState management [closed]

I have been attempting to make a game engine in C++ and have come across the dilemma of game state management. I have done a lot of research and found numerous ways of accomplishing from game engine ...
I Phantasm I's user avatar
-3 votes
1 answer
3k views

What can be the cause of sudden lag spikes in my Android game?

My Android game has sudden lag spikes sometimes. I know this is due to something going wrong. My phone has a 1GHz processor so there shouldn't be a problem. Basically I use the ...
chrypthic's user avatar
  • 111