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
1
vote
2 answers

Android Game loop using a thread postdelayed()

I thought I was being clever using this code for the game thread loop, instead of the usual while(running) loop: @Override public void run() { Log.d(TAG, "+ run()"); final long [] old = new long [] {…
ilomambo
  • 8,290
  • 12
  • 57
  • 106
1
vote
1 answer

Capping frame - rate

Here is the gameloop code that I have implemented into my Android App. It is working great, but the problem I'm having is that although it's capping logic updates at 30 - the actual rendering runs flat out which obviously isn't great for battery…
Zippy
  • 3,826
  • 5
  • 43
  • 96
1
vote
2 answers

Initial states with interpolated fixed time steps

After experimenting a little with variable time steps, I switched to using a fixed time step to update my game objects independently of the current framerate. When things are being rendered, I interpolate each object's position, rotation and so on…
user1925315
  • 67
  • 1
  • 5
1
vote
2 answers

LWJGL Display.update() automatically capping FPS to 60

I am trying to get my game's FPS to go to e.g. 100 and even though I correctly call Display.sync(100); The FPS is 60.. Main loop looks like this: int delta = this.getDelta(); this.update(delta); this.drawGL(); this.updateFPS(); Display.update();…
Matej
  • 9,548
  • 8
  • 49
  • 66
1
vote
2 answers

A simple C# game loop using two threads, is this good?

I'm creating a simple game using GDI+ in C#. First of all I need a game loop, and a render loop. I've decided to break these in to two seperate threads. It seems to work, and runs extremely fast, but the reason I'm asking here is because I see…
Soeholm
  • 1,102
  • 14
  • 15
1
vote
2 answers

Limit draw processing in a game loop

I am using this code structure below from here http://www.koonsolo.com/news/dewitters-gameloop/ to set a game loop that processes based on a set fps but renders/draws at the most possible. How would one implement a cap on the drawing fps so as not…
RustyH
  • 473
  • 7
  • 22
1
vote
0 answers

Interactive input in Python for a nethack/pong game hybrid

Basically I am trying to build a game of pong that plays in the shell. So far the thing stopping me is the user input. The code has to respond to key presses without having to press Return afterwards. I have tried using msvcrt but it does not yield…
Todor Markov
  • 151
  • 9
1
vote
2 answers

How to "randomize" animation in main game loop

I have an animation(see video link below) that is apart of an app I'm working on. I basically have fish swimming across the screen. Currently I have an array of about 20 fish each initially positioned one behind the other, and then "swim" across the…
Jade Byfield
  • 4,668
  • 5
  • 30
  • 41
1
vote
0 answers

How to efficiently draw 2d with openGl es?

Originally I was using the canvas to draw my bitmaps in a 2d real time action type game, but for some reason my frame rate was terrible. I suspected it was the canvas so I switched to opengl. From surfing on the internet I learned to create a…
Sharkbird
  • 61
  • 6
1
vote
1 answer

Game loop with multiple objects callback - nothing happens with second Object

I have two classes, both inherited from the same base class. It's for a game loop and depending on which "state" you're in, it should send a pointer to the active object in the CALLBACK method - but it doesn't. It only sends the second object's…
Deukalion
  • 2,516
  • 9
  • 32
  • 50
1
vote
2 answers

How to pause loop to wait for button press

I'm trying to create a turn based game using a 1v1 battle for android. My basic game loop checks if the two fighters are dead, if not then checks who is to go next. If its the player's turn then it should wait for an attack button to be clicked. If…
willmer
  • 233
  • 1
  • 4
  • 12
1
vote
1 answer

gameloop framerate control issues

this is driving me mad, anyway, usual story, attempting to guarantee the same speed in my very simple game across any windows machine that runs it. im doing it by specifying a 1/60 value, then ensuring a fram cant run until that value has passed in…
cool mr croc
  • 725
  • 1
  • 13
  • 33
1
vote
3 answers

Game Loop frame independent

Is it admissible to let the game loop run as fast as possible? Currently I can set my desired fps, thus having a constant fps on all devices my game will ship to. Yet on faster mobile devices it would be nicer to have smoother graphics. I had a look…
Luke Taylor
  • 9,481
  • 13
  • 41
  • 73
1
vote
2 answers

How is it possible to use dual core in opengl game loop?

My question is about game loop design in opengl. I believe that game loop can be spited in 3 main steps accept input - it may come from users click on the screen or system alert, or anything else. do logic update view To make it simple let's just…
Ilya Gazman
  • 31,250
  • 24
  • 137
  • 216
1
vote
1 answer

SDL - FPS problems with LoopTimer in c++

We're making a game engine for our c++ class, and we're mostly done with everything except we're having some minor issues with the FPS. It always runs about 10-20% slower than what we set it to, and we're wondering if this is due to a bug/crappy…