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

Lag in Game Loop as the game progresses

Here is my small attempt at working with Game Loop. Here is the Demo. (keep clicking in gray area to start it). The issue is that the game animations get choppy after clicking for a while, and reach to a point where it's like a stop motion thing,…
md1hunox
  • 3,815
  • 10
  • 45
  • 67
0
votes
0 answers

Delaying events in a game loop with Android?

If you have a game loop thread in Android that draws to a surfaceview and you require a couple of seconds delay to perform animation, how do you go about doing this?
Fenix
  • 188
  • 10
0
votes
2 answers

in a game loop, why do you need a separate update and draw call?

most likely a dumb question, but can't you both update and redraw everything at once in a single function rather than calling two functions back to back, what's the advantage of updating then drawing?
0
votes
1 answer

Why does var yPosition increment after each loop despite no event occurring?

var canvas = document.getElementById('gameCanvas'); var ctx = canvas.getContext('2d'); var xPosition = 0; var yPosition = 0; var frameLength = 20; function gameLoop(){ gameUpdate(); setTimeout(function(){gameLoop()},…
Jake L.
  • 11
  • 1
0
votes
3 answers

Time Step in PhysX

I'm trying to define a time step for the physics simulation in a PhysX application, such that the physics will run at the same speed on all machines. I wish for the physics to update at 60FPS, so each update should have a delta time of 1/60th of a…
fanatic
  • 143
  • 2
  • 9
0
votes
1 answer

Why does a game loop need to sleep?

Why does the game loop need to sleep and how do you determine for how long? How do you keep the sleep time of a thread constant?
0
votes
1 answer

The paddle of pong keeps shaking without staying at one position

Please look at the following structure of my pong game. gameLoop(); method //Only run this in another Thread! private void gameLoop() { //This value would probably be stored elsewhere. final double GAME_HERTZ = 30.0; …
user3059427
  • 209
  • 2
  • 3
  • 10
0
votes
1 answer

How to implement turns while still executing the main loop?

I am creating a trading game in Python, and want to know how to implement turns without pausing the gameloop. I know that I will have to change the way movement is implemented, but how would I do that? Note: code can be reached here (May be old):…
Pip
  • 4,387
  • 4
  • 23
  • 31
0
votes
0 answers

gameloop thread crash onresume

i am just finishing up a small game i did, second one, based on code done by java4edu: http://www.edu4java.com/en/game/game0-en.html however after my mods, i have run to a glitch where whenever i , resume, rotate screen, change the screen to (load…
0
votes
1 answer

Opengl: How do time based tetris game?

I am working on a basic tetris game for school. I am not sure how can i develop a game loop since this is my first time making a game. I am using opengl to do the drawing. Do I make a main loop that will wait certain amount of time before it…
LittleFunny
  • 8,155
  • 15
  • 87
  • 198
0
votes
0 answers

Android 2D game: who should be responsible for calling the canvas to draw?

In online tutorials or in the Android SDK samples of 2D games, there is usually a drawing function inside the game thread's run() method, which is responsible for drawing on the canvas. For instance, in the classical Lunar Lander code, we have the…
user740006
  • 1,759
  • 4
  • 20
  • 30
0
votes
3 answers

Strange behavior of java game loop

I have a simple game loop in java: public void run(){ while(running){ start = System.nanoTime(); gamePanel.update(); gamePanel.repaint(); elapsed = System.nanoTime() - start; wait = (TARGET_TIME - elapsed)…
T_01
  • 1,256
  • 3
  • 16
  • 35
0
votes
3 answers

Game Loop - Elements get faster the longer they exist

In my game, I have multiple threads. One thread sends signals to the calculation-threads, after this thread receives signals, it also renders the game. The main thread looks like this, which I adapted from some other game-loop I've…
damian
  • 2,001
  • 20
  • 38
0
votes
1 answer

How to approach game level switching

What is the best approach to switch to different scenes/areas in a 3D game from the render area? Say you have a character and he moves into a new area, how would you go about unloading the area and loading the new area. Would you just load the…
0
votes
3 answers

How do I make a "loop" for a game, that runs every (number) of milliseconds?

I've tried to search for this on google and stackoverflow, but I'm not sure what to call it, so I can't find it. How would I make a "loop" for the C# program, that runs every, say, 100 milliseconds? Similar to what Minecraft calls "ticks", or…
Dominoed
  • 123
  • 3
  • 15