Questions tagged [game-loop]

The central component of any game, from a programming standpoint, is the game loop. The game loop allows the game to run smoothly regardless of a user's input or lack thereof.

The game loop is the central component of any game and it is generally split into three different pieces: initialization, update, and draw (or render).

During the initialization phase, the game is set up and the environment is prepared for the update and draw routines.

During the update phase, all of the objects and components of the game are updated based on the game's logic, user's input and the time since the last update routine.

During the draw or render phase, all of the objects and components of the game are drawn or rendered to the viewport based on the most recent update.

Once the current frame is rendered, the game loop repeats the execution of the update statements based on the new delta time and then renders again.

485 questions
52
votes
11 answers

Why is a "main" game loop necessary for developing a game?

I find that most game development requires a main game loop, but I don't know why it's necessary. Couldn't we implement an event listener and respond to every user action? Animations (etc.) could then be played when a event occurs. What is the…
Tattat
  • 15,548
  • 33
  • 87
  • 138
26
votes
9 answers

Lua, game state and game loop

Call main.lua script at each game loop iteration - is it good or bad design? How does it affect on the performance (relatively)? Maintain game state from a. C++ host-program or b. from Lua scripts or c. from both and synchronise them? (Previous…
topright gamedev
  • 2,617
  • 7
  • 35
  • 53
25
votes
7 answers

Best way for simple game-loop in Javascript?

Is there a simple way to make a game loop in JavaScript? something like... onTimerTick() { // update game state }
noctonura
  • 12,763
  • 10
  • 52
  • 85
19
votes
5 answers

Annoying lags/stutters in an android game

I just started with game development in android, and I'm working on a super simple game. The game is basically like flappy bird. I managed to get everything to work, but I get a lot of stutters and lags. The phone I'm using for testing is LG G2,…
Asaf
  • 2,005
  • 7
  • 37
  • 59
19
votes
2 answers

android game loop vs updating in the rendering thread

I'm making an android game and am currently not getting the performance I'd like. I have a game loop in its own thread which updates an object's position. The rendering thread will traverse these objects and draw them. The current behavior is what…
user1578101
  • 215
  • 1
  • 2
  • 7
18
votes
2 answers

How do I write a game loop in Haskell?

I want to code a game in Haskell where every iteration of the loop computes the state of the world. I thought I should create a function: gameLoop :: World -> World -- ... and have main :: IO () call it: main = do gameLoop -- ... But the…
sdasdadas
  • 23,917
  • 20
  • 63
  • 148
16
votes
6 answers

Algorithm for Client-Server Games

For stand alone games, the basic game loop is (source: wikipedia) while( user doesn't exit ) check for user input run AI move enemies resolve collisions draw graphics play sounds end while But what if I develop client-server-like games,…
Click Ok
  • 8,700
  • 18
  • 70
  • 106
14
votes
2 answers

Node.js: alternative to setInterval which is more precise for game loop

My setup is a multiplayer game, with sockets to async transfer data. Now because of the nature of a game, I have a game loop which should tick every 500ms to do player updating (e.g. position, appearance,...). var self = this; this.gameLoop =…
Captain Obvious
  • 745
  • 3
  • 17
  • 39
13
votes
1 answer

Android: Understanding OnDrawFrame, FPS and VSync (OpenGL ES 2.0)

For a while now I've experienced an intermittent 'stuttering' of the sprites that are in motion within my Android Game. It's a fiarly simple 2D OpenGL ES 2.0 game. (This is an ongoing problem which I have re-visited many times). In my game loop, I…
Zippy
  • 3,826
  • 5
  • 43
  • 96
11
votes
1 answer

Best way to make game loop for Android using OpengGLSurface

From what I've seen, if I wanna make a NON-opengl game loop what I can do is have a game thread that during the loop will update the game state (or game physics) and also update the graphics by locking a Canvas from a (normal) SurfaceView, doing the…
Shivan Dragon
  • 15,004
  • 9
  • 62
  • 103
11
votes
1 answer

Custom XNA Game loop in Windows

I'm trying to figure out how to manage the whole game loop manually in a Windows game, without using the regular Game Microsoft.Xna.Framework.Game class. The reason for this is using the regular Game class causes some stuttering in my game. Not…
sinsro
  • 905
  • 7
  • 25
11
votes
4 answers

Steady_Clock skipping between updates in main game loop

In the process of trying to work out a solid game loop in SFML I came across this issue which I can't seem to figure out. I was able to strip out all of the SFML code and still see the issue with clock() in time.h. Then I went further and still see…
S. Turnage
  • 111
  • 5
10
votes
3 answers

Best way to implement game loop without freezing UI thread

I'm trying to make a simple 2D game in Java. So far I have a JFrame, with a menubar, and a class which extends JPanel and overrides it's paint method. Now, I need to get a game loop going, where I will update the position of images and so on.…
Matthew H
  • 5,831
  • 8
  • 47
  • 82
9
votes
3 answers

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 couple of articles, tutorials and code from other…
rfgamaral
  • 16,546
  • 57
  • 163
  • 275
9
votes
1 answer

In JavaFX how do I move a sprite across the screen?

I'm new to JavaFX and am trying to write a game where an animated 2D character walks across the screen (for example like the original Legend of Zelda game). I had done this in Swing, by creating my own Sprite class and overriding the…
Zareh
  • 1,225
  • 2
  • 9
  • 6
1
2 3
32 33