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
0 answers

OpenGL draw a line then a square

I am having problem managing my code and imagining a good design. What i wanna do is simply draw a line first, then after line has been rendered, draw the square so it overlaps the line partially and then keep on doing this. I created 2 classes,…
gallickgunner
  • 472
  • 5
  • 20
0
votes
1 answer

Only Evaluates as True when Thread Sleeps

I am getting some unexpected behavior I don't understand. I am trying to implement a fixed variable time step as described from http://gafferongames.com/game-physics/fix-your-timestep/ and http://gameprogrammingpatterns.com/game-loop.html. My inner…
leaflet757
  • 159
  • 1
  • 1
  • 9
0
votes
3 answers

Java - How to block a running thread for an exact amount of time?

I need my main Thread to block for a specific amount of time. I am currently working on a 2D game and it's pretty laggy just because the Thread.sleep(2) sleeps for ~17 seconds and when you move the character, graphics are lagging slightly. Sometimes…
user263980
  • 31
  • 1
  • 6
0
votes
1 answer

60 FPS Game Loop on Universal Windows Platform Direct3D C++ App

pretty new on the C++ side of windows - special non-Win32 such as UWP - I am trying to cap FPSs at a steady 60 FPS by simply ticking (Update/Render) every 1000/60 milliseconds. I am facing a strange situation though. If I am using Present(0,0), the…
Fer
  • 460
  • 2
  • 4
  • 17
0
votes
3 answers

java image appears and disappears when using game loop

game loop: private int FPS = 25; private int targetTime = 1000 / FPS; public void run(){ init(); long start; long elapsed; long wait; while (running){ start = System.nanoTime(); init(); repaint(); …
0
votes
1 answer

libgdx snake logic explained

This is the code from a book I am reading. It is just a snake game. you can paste this code into editor and change 3 texture files to what you have on computer. The code works fine and this is probably really stupid, but I am unable to make the…
potato
  • 4,479
  • 7
  • 42
  • 99
0
votes
1 answer

Sleep/Wait without consuming CPU

So I am simulating this smartphone app to Windows. It's a game that runs it's logic and draw methods at a 1/60 rate. In milliseconds this is 16.6667 I've implemented this game loop: private const double UPDATE_RATE = 1000d / 60d; private…
kevintjuh93
  • 1,010
  • 7
  • 22
0
votes
0 answers

How to disable texture in case of LEVEL UNLOCK SYSTEM IN UNITY?

I am building a game consist of 8 levels. I use the following script to switch next level. But when I unlock a level the Lock Texture still remain in the window. I want to remove the lock texture when i unlock a new level. Please help me out. The…
Fazle Rabbi
  • 1
  • 4
  • 16
0
votes
1 answer

C++ Win32 FPS and DeltaTime Implementation

I'm trying to implement FPS and DeltaTime for my program (C++ Win32). Below is the current code that I have. FPS and DeltaTime should have been implemented in the right manner. If not, please tell me how I may fix my problem. The current problem I…
JekasG
  • 161
  • 1
  • 5
  • 14
0
votes
2 answers

android translate canvas co-ordinates when the moving bitmap inside it closes to the right border of the screen?

i have bitmap moves to right inside canvas i want when this bitmap closes to the right border of screen i.e : x position < getWidth() with certain small value i want to translate canvas co-ordinates so that the canvas itself moves also along side…
omar
  • 41
  • 1
  • 9
0
votes
1 answer

Window stops refreshing when key is pressed

Whenever I press a key to move a sprite, the screen will not update until I release the key. The only way I've been able to fix this is to clear, draw, and display the window within each and every KeyPressed loop. It makes much more sense to do each…
Jager57
  • 3
  • 2
0
votes
1 answer

Should System.nanoTime() in Java be explicitly casted to a double for game loop?

I am writing a game loop in Java and trying to calculator deltas. When attempting to get the current time, the following does not give me an error in my IDE. However the function returning a double, where are System.nanoTime() return a long. Why is…
user68653
  • 5
  • 3
0
votes
2 answers

Where should I save data using Shared Preferences in the game loop in Android?

Well trying to program a simple game in Android, I cam across the problem of saving data. I went the route of using simple Key Value pairs using Shared Preferences, mostly because I'm only saving 10 - 15 simple Integers. But I cant save it in the…
0
votes
1 answer

C++ Jittery game loop - how to make it as smooth as possible?

This is my gameloop code: while (shouldUpdate) { timeSinceLastUpdate = 0; startTime = clock(); while (timeAccumulator >= timeDelta) { listener.handle(); …
Accumulator
  • 873
  • 1
  • 13
  • 34
0
votes
1 answer

Animation ist only smooth when ontouchevent is called

i'm making my first 2d sidescroller game using a surfaceview and a canvas to draw things on (a lot of primitives put in different path objects). my game loop uses fixed timesteps with linear interpolation. i don't create any objects during the game.…