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
6
votes
1 answer

Should I always use a Gaming Loop in a Silverlight Game?

I have read about using CompositionTarget.Rendering Timer for the primary gaming loop in silverlight. To be used for hit testing and general game logic as would be done in any language. This said I was wondering is it best to move objects around…
John
  • 29,788
  • 18
  • 89
  • 130
6
votes
2 answers

Allegro 5 game: game loop that runs at constant speed?

What is the best way to code a game loop in Allegro 5 that always runs at the same speed, and that properly separates drawing logic from update logic? Should I use threads or not? Should I make use of the new Allegro event system?
amarillion
  • 24,487
  • 15
  • 68
  • 80
5
votes
2 answers

memory leak on game loop

I am creating a game in javascript and my gameloop is called every 30ms, it leaks a lot of memory as task manager shows the firefox memory usage to increase by 400mb in about 20 seconds. I am not familiar with how to make sure memory is collected in…
code_by_night
  • 253
  • 2
  • 4
  • 14
5
votes
4 answers

Why use integration for a fixed timestep game loop? (Gaffer on Games)

http://gafferongames.com/game-physics/fix-your-timestep/ http://www.koonsolo.com/news/dewitters-gameloop/ In the last game loop from Glenn Fiedler's Fix Your Timestep! article, he uses an update loop that advances the game logic by a fixed delta…
YeOldeBitwise
  • 133
  • 1
  • 2
  • 8
5
votes
1 answer

Is this a good implementation of a FPS independant game loop?

I currently have something close to the following implementation of a FPS independent game loop for physics based games. It works very well on just about every computer I have tested it on, keeping the game speed consistent when frame rate drops. …
Nick Van Brunt
  • 15,244
  • 11
  • 66
  • 92
5
votes
2 answers

How should I use requestAnimationFrame and setTimeout in parallel to make a better game loop?

My goal is to create an efficient game loop that uses requestAnimationFrame for updating the display canvas and setTimeout for updating the game logic. My question is should I put all the drawing operations inside the requestAnimationFrame loop or…
Frank
  • 2,050
  • 6
  • 22
  • 40
5
votes
2 answers

in AS3, removeEventListener(Event.ENTER_FRAME) is not working

I have been dealing with this problem for days already. I am at my wits' end! I can't seem to find a definitive answer anywhere on any of the forums, documentation, etc. Everything looks fine at first run, or when I load a next level for the user to…
5
votes
1 answer

What's the proper way to write a game loop in Python?

I'm trying to write a python game loop that hopefully takes into account FPS. What is the correct way to call the loop? Some of the possibilities I've considered are below. I'm trying not to use a library like pygame. 1. while True: …
jastr
  • 881
  • 1
  • 9
  • 19
5
votes
2 answers

Win32 game loop that doesn't spike the CPU

There are plenty of examples in Windows of applications triggering code at fairly high and stable framerates without spiking the CPU. WPF/Silverlight/WinRT applications can do this, for example. So can browsers and media players. How exactly do they…
Rei Miyasaka
  • 7,007
  • 6
  • 42
  • 69
4
votes
4 answers

Avoiding game loop in XNA 4.0

I developing a simple 3D model viewer on XNA 4.0. Is there a way to avoid a infinite game loop with Draw and Update functions? I need render 3D graphics, but without infinite rendering of scene. I mean I need redraw the scene only then it really…
Yury
  • 1,169
  • 2
  • 16
  • 29
4
votes
4 answers

Functional Alternative to Game Loop

I'm just starting out with the Scala and am trying a little toy program - in this case a text based TicTacToe. I wrote a working version based on what I know about scala, but noticed it was mostly imperative and my classes were mutable. I'm going…
whaley
  • 16,075
  • 10
  • 57
  • 68
4
votes
2 answers

Java TimerTick event for game loop

I tried making a game loop in Java using the Timer from java.util.Timer. I am unable to get my game loop to execute during the timer tick. Here is an example of this issue. I am trying to move the button during the game loop, but it is not moving on…
Johnathan
  • 787
  • 4
  • 10
  • 21
4
votes
1 answer

How does delta_time work on python arcade?

I’m going through the tutorials on python arcade and would like to know how/why a function works. There is a function named on_draw(delta_time) I looked around the code for arcade but can’t figure out how the library knows to keep the clock running.…
user1026169
  • 5,345
  • 5
  • 21
  • 35
4
votes
5 answers

How to make timer for a game loop?

I want to time fps count, and set it's limit to 60 and however i've been looking throught some code via google, I completly don't get it.
Neomex
  • 1,650
  • 6
  • 24
  • 38
4
votes
1 answer

SDL FrameRate cap implementation

I'm really new to game development and I've already made a few programs using SDL2. Frame rate wasn't much of an issue since I never planned to release those programs and just used the SDL_RENDER_PRESENTVSYNC to cap the frame rate to 60 (the refresh…
CookingMama
  • 51
  • 1
  • 4
1 2
3
32 33