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.

The game loop is designed to ensure the persistence of action in a game. Unlike many other software applications, games do not stall and wait for input. The world continues to run while the player watches, which importantly allows timing to play a role.

The game loop is responsible for allowing this, by continually rendering the scene without requiring the player's input. A rudimentary game loop might run like the following:

  1. Accept player input if any exists, resolve actions for player as a result of any input
  2. Resolve AI decisions and actions
  3. Determine collisions and resolve their impact
  4. Render the resulting scene

Use this tag when you're asking questions such as the proper structure, optimization and efficiency strategies, or debugging errors in the main game loop code.

482 questions
16
votes
9 answers

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 I'm using Array but I plan to change to Vector…
Iain
  • 6,518
  • 3
  • 33
  • 46
15
votes
2 answers

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 update(FIXED_INTERVAL) calls followed by one…
Ryan
  • 887
  • 2
  • 8
  • 10
12
votes
2 answers

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 it was inside the loop itself. How to make it so…
GSquadron
  • 307
  • 4
  • 11
6
votes
3 answers

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" for a game. I guess that the "age" attribute…
J. Doe
  • 63
  • 5
5
votes
2 answers

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 menu. Should my game loop look like this: if…
Justin
  • 1,386
  • 12
  • 22
5
votes
3 answers

Speed, delta time and movement

player.vx = scroll_speed * dt /* Update positions */ player.x += player.vx player.y += player.vy I have a delta time in miliseconds, and I was wondering how I can use it properly. I tried the above, but that makes the player go fast when the…
David Gomes
  • 565
  • 2
  • 7
  • 15
4
votes
1 answer

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 nearly 100%. I understand that this is desired…
Lukas Knuth
  • 155
  • 1
  • 6
3
votes
2 answers

Should I redraw every pixel?

For my first game I implemented a tetris clone in javascript. My "canvas" and an HTML with every
representing a single block. Instead of having a gameloop redraw every single pixel, I only update pixels that have changed, like a piece…
PBG
  • 173
  • 1
  • 1
  • 5
3
votes
1 answer

Varying framerate (FPS)

In my game-loop, I am using fixed time step for physics and interpolation for rendering as suggested on Gaffer on Games | Fix Your Timestep! However, when the framerate is varying between 30-60fps during the game, the game looks jumpy. For example,…
Buddy
  • 131
  • 5
2
votes
1 answer

How to precisely limit fps

I am having trouble making my game's main loop to run at exactly N fps. Let's say i want game to run at constant 60 fps. Here is part of my code: int ticksPerSecond = 60; int skipTicks = 1000 / ticksPerSecond; int maxFrameskip = 10; //…
Skull
  • 21
  • 5
2
votes
2 answers

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... Fixed Physics Step: If I fix my physics step because…
NovaCrist
  • 383
  • 1
  • 10
1
vote
8 answers

Games development with a game loop that's abstracted away

Most game development happens with a main game loop. Are there any good articles/blog posts/discussions about games without a game loop? I imagine they'd mostly be web games, but I'd be interested in hearing otherwise. (As a side note, I think…
Davy8
  • 824
  • 1
  • 5
  • 16
1
vote
3 answers

Triggering State Changes with Health Counter

I'm developing a game where the player changes states as their health decreases. Below 50, it should trigger animation1. Below 30, it should trigger animation2. The problem is, I only want to trigger animation1 once. But my game timer is checking…
1
vote
3 answers

What are the pros and cons of a non-fixed-interval update loop?

I am studying various approaches to implementing a game loop, and I have found this article. In the article, the author implements a loop which, if the processing falls behind in time, skips frame renderings and just updates the game in a loop (the…
akonsu
  • 113
  • 3
1
vote
3 answers

Long delta time and collision detection

When player's computer stutters/he tabs out of game stopping requestAnimationFrame calls, movement system tied to the delta time creates a huge leap, bypassing probable collisions. This allows player to cheat, for example avoiding projectiles by…
Misiur
  • 143
  • 5
1
2