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

Hangman game in Python - my break seems to only work every OTHER time the game is played

as the title suggests, the game works fine, but it seems I've got a bug that I cannot figure out. After the first game, when it asks if you'd like to play again, it proceeds with the next game just fine, you can play that one, then finally after…
0
votes
1 answer

Render loop - maximum parallelization

Below is a UML sequence diagram showing processing time on my understanding of the game loop in the library libGDX. I think it should be the same architecture for every other game library. I am not sure if I understood it correctly. In theory CPU…
Benedikt S. Vogler
  • 554
  • 1
  • 5
  • 19
0
votes
1 answer

My Game loop accelerates and character leaves a trail

The code: // create stuff var ghObj = { x : 0, y : 0 } var canvas = document.getElementById("canvas"); var ctx = canvas.getContext("2d"); var ghost = new Image(); ghost.src = "ghost.png" //define variables var ghostMove = function () { …
Rich Cat
  • 17
  • 5
0
votes
2 answers

Win32 game loop

I'm creating simple game using Win32 API. When I click on window, a ball appear and start rolling look like bida game My problem is when I call "InvalidateRect", my game very lag. I don't know I'm doing any thing wrong!!! And my hPen didn't work…
0
votes
1 answer

Hex grid in game loop with camera controls, jittering issue (due to faulty positions?)

I'm fairly new to programming but I've managed to learn how to set up a basic game loop with left/right/up/down controls. The only problem is that when the camera moves there are graphical glitches (jittering back and forth). I've looked into double…
lm300Q
  • 1
  • 1
0
votes
1 answer

Qt stop key events for a short period for a game loop

I am overriding keyPressEvent to move a player across a QGraphicsScene. The player has an animation which takes 1000ms (which should complete before continuing). My problem is that if the user holds down the key it will send loads of events and it…
ovg
  • 1,486
  • 1
  • 18
  • 30
0
votes
2 answers

A simple 30fps game loop in javascript using requestAnimationFrame?

I am writing a card game so i need to setup a basic game loop using window.requestAnimationFrame. I need to make the fps set to 30fps and since it is a slow paced card game i just need a simple workable game loop. My game loop is as follows.…
kofhearts
  • 3,607
  • 8
  • 46
  • 79
0
votes
1 answer

Cannot get smooth movement in SFML

I searched on this topic and found that using sf::Clock to implement frame independent update(using deltaTime) can help to solve it. However even after adding it the paddle movement stutters a bit. On the other hand when I shift the entire Playing…
Karan Joisher
  • 331
  • 1
  • 9
0
votes
1 answer

Making thread.sleep accurate

I am attempting to make a game loop that has an accurate timer. I know that TimeUnit uses thread.sleep(); which can vary by milliseconds. My question is simple: Does this code make thread.sleep(); more accurate? and further Is there anything I can…
cat16
  • 33
  • 9
0
votes
1 answer

Start a new CountDownTimer inside a run method

I am new to android development, and I am trying to create a little game. I have my first CountDownTimer created by the constructor in my GameView subclass of SurfaceView. What I should do in order to pass on the next level, is call the cancel() of…
ldg
  • 450
  • 3
  • 7
  • 27
0
votes
1 answer

My first roll a dice python game

import random def diceroll(): num_dice = random.randint(1,6) print("You got " + str(num_dice) + "!") diceroll() def question(): response = input("You want to roll again?\n") while response == "y": diceroll() …
0
votes
0 answers

When calling a JPanel to run from a button clicked from another class running a JFrame, it only displays the JFrame of the other class not panel

The Game class calling the window class int he constructor the print it's contents on a JFrame. public class Game extends javax.swing.JPanel { public Game() { initComponents(); addKeyListener(new KeyListener() { …
0
votes
0 answers

Pygame Def gameLoop not updating

I want to create a GameOver screen with the option to "Play Again" using KEYDOWN event. The quit option works but my gameloop does not update. When I type gameLoop() the font doesn't turn blue. My Code: def gameLoop(): gameExit=False …
0
votes
1 answer

How to make fixed timestep in Java

How should we make fixed timestep in Java? I think there are 2 ways: Synchronised game loop using while. Asynchronised game loop using Thread. The most important thing is performance and accuracy. So what's the best way? This is synchronised game…
Szymon Marczak
  • 1,055
  • 1
  • 16
  • 31
0
votes
0 answers

Python 3.x Proper way to make gameloop in tkinter?

I am making a game in tkinter, and I was wondering if there was a proper way to make a game loop. With the current gameloop, whenever I update an object's position, It can be blurry. Here is my current gameloop: self.running = True while…
Logan Darby
  • 145
  • 16