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
9
votes
6 answers

How to show alert dialog in a running thread?

I'm developing an Android Game.In this game, There are tracks on which trains run. This is running thread. I want to show an alert dialog when there is a collision between. when I'm applying alert dialog showing error can't create handler inside…
user1602798
  • 365
  • 3
  • 5
  • 13
8
votes
4 answers

Android game with constant FPS?

I'm implementing a game loop with constant FPS. I'm thinking about 25-30 FPS should be enough. Any ideas from your own experience? Should I even restrict FPS at all?
sinek
  • 2,458
  • 3
  • 33
  • 55
8
votes
2 answers

How to safely decouple rendering from updating the model?

Talking with some game developers, they suggested that a performant OpenGL ES based game engine does not handle everything on the main thread. This allows the game engine to perform better on devices with multiple CPU cores. They said that I could…
Proud Member
  • 40,078
  • 47
  • 146
  • 231
8
votes
1 answer

Does "deWiTTERS Game Loop" assume a constant UPS?

I recently tried to get into games programming. I am pretty experienced with Java, but not with game programming. I read http://www.koonsolo.com/news/dewitters-gameloop/ and implemented the game loop proposed there with the following code: private…
BlackWolf
  • 5,239
  • 5
  • 33
  • 60
7
votes
1 answer

Where should I put the game loop in the swing app?

I'm trying to make a simple 2D game in Java. As far as I know, my game should consist of two threads: "event dispatch thread" (for GUI operations) and "game thread" (for game loop). I created an outline but could not find where to place the game…
7
votes
1 answer

Gaffer on games timestep: std::chrono implementation

If you're not familiar with the Gaffer on Games article "Fix your Timestep", you can find it here: https://gafferongames.com/post/fix_your_timestep/ I'm building a game engine, and in an effort to get more comfortable with std::chrono I've been…
Josh Sanders
  • 750
  • 10
  • 21
7
votes
2 answers

Are there best practices for implementing an asynchronous game engine loop?

I have implemented a game engine loop as follows: public static Boolean Start ( ) { if (hasBoard) { // start engine on worker thread asyncTask = new AsyncResult ( stopEngine, asyncTask ); isRunning =…
IAbstract
  • 19,551
  • 15
  • 98
  • 146
7
votes
2 answers

Where to place main game loop in android game

I am trying to write some skeleton for a game on android, using OpenGL. I would like to know, where should I place my main game loop code? So far, my best candidate is Renderer.onDrawFrame(...) method, which seems to be called per-frame, so the code…
SadSido
  • 2,511
  • 22
  • 36
7
votes
7 answers

Design pattern for modeling two competing objects

I'm trying to figure out the best design pattern to use for managing a "competition" between two interacting objects. For example, if I want to have a Fox class that chases a Rabbit class through a simple environment. I want to let them "compete"…
emersonthis
  • 32,822
  • 59
  • 210
  • 375
6
votes
3 answers

Simple Game in C# with only native libraries

I could find a set of java 2D game tutorials and android game tutorials which uses only native graphics libraries. I'm looking for something similar in C# ( without DirectX or XNA) I found this game loop skeleton , but it doesn't tell how to Render…
Dinushan
  • 2,067
  • 6
  • 30
  • 47
6
votes
1 answer

Rust lang thread::sleep() sleeping for almost twice the specified time during game loop on windows

So I've written the following function to show what i mean: use std::{thread, time}; const TARGET_FPS: u64 = 60; fn main() { let mut frames = 0; let target_ft = time::Duration::from_micros(1000000 / TARGET_FPS); println!("target frame…
user11165129
6
votes
1 answer

Game-Loop in Firemonkey for Android

im currently making a 2D game in Firemonkey for my Android phone using some TImage Controls and controling their positions and angles. Simple as that. I tried to use my normal way of looping, which works well/flawless in Windows but fails on…
KoalaGangsta
  • 397
  • 1
  • 17
6
votes
3 answers

Game loop in Win32 API

I'm creating game mario like in win32 GDI . I've implemented the new loop for game : PeekMessage(&msg,NULL,0,0,PM_NOREMOVE); while (msg.message!=WM_QUIT) { if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { TranslateMessage(&msg); …
Dzung Nguyen
  • 9,152
  • 14
  • 65
  • 104
6
votes
7 answers

Help with game development. Render loop?

I'm working on a simple game, this is my first game project. Most of the samples I find have a Render Loop where all the game logic is made too and I just don't like this. Let's say I have a ball with X=0, and a wall in X=10 and in a slow machine,…
John
  • 83
  • 1
  • 3
6
votes
3 answers

DirectX: Game loop order, draw first and then handle input?

I was just reading through the DirectX documentation and encountered something interesting in the page for IDirect3DDevice9::BeginScene : To enable maximal parallelism between the CPU and the graphics accelerator, it is advantageous to call …
Ricket
  • 33,368
  • 30
  • 112
  • 143
1
2
3
32 33