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
256
votes
11answers
89k 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 ...
40
votes
5answers
9k 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 <...
130
votes
3answers
79k views

How should I write a main game loop? [closed]

How should I write a 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 the game loop? I've written plenty of them, but I've ...
74
votes
5answers
13k 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: ...
36
votes
3answers
20k 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 ...
15
votes
2answers
10k 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 ...
27
votes
2answers
10k 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.
19
votes
2answers
5k 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 ...
18
votes
3answers
5k 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 ...
30
votes
2answers
30k 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 ...
6
votes
1answer
3k 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, ...
32
votes
3answers
25k 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
3answers
2k 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 ...
19
votes
1answer
3k 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 ...
16
votes
9answers
2k 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 ...
10
votes
2answers
20k 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 ...
3
votes
1answer
4k 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 ...
9
votes
2answers
1k 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". (...
1
vote
2answers
627 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 ...
0
votes
2answers
607 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: ...
14
votes
2answers
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 ...
20
votes
5answers
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. ...
16
votes
3answers
6k 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 ...
8
votes
2answers
4k 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 ...
8
votes
1answer
547 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 ...
7
votes
3answers
2k views

What are “frame rate” and “fps?”

Can someone give me a detailed explanation about frame rate and fps concepts?
7
votes
1answer
6k 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 ...
7
votes
2answers
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 ...
10
votes
2answers
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 (...
8
votes
2answers
5k 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: ...
4
votes
1answer
1k views

Java Game Loop Efficiency

I'm quite new to java. 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 ...
0
votes
3answers
4k 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 ...
4
votes
2answers
587 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 ...
3
votes
1answer
1k 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: ...
3
votes
3answers
1k 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 ...
4
votes
3answers
879 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 ...
3
votes
2answers
6k 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 ...
2
votes
5answers
5k 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?
1
vote
1answer
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 ...
2
votes
2answers
434 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... ...
2
votes
4answers
1k 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 ...
2
votes
1answer
368 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 ...
1
vote
2answers
78 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 ...
1
vote
1answer
2k 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 ...
0
votes
1answer
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 ...
-3
votes
1answer
2k 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 ...