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

How to achieve butter smooth motion in pixi.js (without any lags / spikes)

I'm trying to achieve butter smooth motion using pixi.js. It should be a simple thing I suppose but it seems I can't obtain it. Sometimes I get spikes / micro lags. I've tested it on my Ubuntu 20.04 dev machine using the latest Chrome version and…
Marco Ferragina
  • 543
  • 1
  • 4
  • 12
0
votes
0 answers

PixiJS Update loop & delta

When using PixiJS, I noticed that sprites that I move in a straight line at constant speed sometimes "jump" seemingly randomly - usually falling slightly behind their expected position. This is especially noticeable with fast-moving projectiles. I…
Ben
  • 15,938
  • 19
  • 92
  • 138
0
votes
2 answers

React state updated properly except inside gameloop function

I have this very simple react code that declares a state variable called money using the useState hook. Then I trigger a gameloop to start once using the useEffect hook. Inside this gameloop, I simply increment the value of the money state…
Palmi
  • 3
  • 2
0
votes
1 answer

Set frame redraw rate in glium?

I am trying to make a game loop using glium in rust. My goal is to get the screen to redraw 60 times per second. With the current event loop code I have, the frame only gets redrawn when the window size changes. I read in the glutin docs, that I…
Ian Rehwinkel
  • 2,486
  • 5
  • 22
  • 56
0
votes
1 answer

Global variable set and then reset in Python Canvas

Good afternoon, I'm building out (suppose to be) a relatively simple q & a experiment for a psychology experiment. I'm using Pythons canvas for drawing and painting but have hit a bit of brick wall and a classic update scenario, I think. Here's the…
Katana24
  • 8,706
  • 19
  • 76
  • 118
0
votes
1 answer

Stuck on using Java Swing Timer

I have created a small rectangle in a canvas which is on a JFrame. I have made the class a singleton (I know some of you will say it's bad practice, but i'm fine with that). I am currently just using the repaint() method whenever an arrow key is…
0
votes
0 answers

Understading general Game Looping

I've been reading some materials over internet related this topic but I'm still lazy. This was the last I read and got me the best knowledge about how to struct the general idea, however, with my tests, I don't know if I got the loop works fine for…
Lucas Sousa
  • 192
  • 3
  • 14
0
votes
0 answers

My code doesn't work when I switched OS to Mac

I don't like posting these kind of problems. But this time I really don't know what happened. I wrote this code on PC and it worked fine. However on my Macbook it doesn't work. It gets stuck in the second loop it seems like? Is there a way to…
Dubstepzedd
  • 148
  • 1
  • 9
0
votes
1 answer

Limiting the frames per second for a text based game running in command prompt

This is a follow up question to the comments in my last question. I was told that the command prompt screen is flickering because i didnt limit the frames per second. I have been doing some research on how to limit frames per second and i found…
user12291970
0
votes
2 answers

Clearing the screen for text based rpg in python

I am trying to make a text based rpg game in python. I just started and this is what my code looks so far: class Game: def __init__(self): self.map = [[" " for i in range(50)]for i in range(30)] def draw_map(self): for i in…
user12291970
0
votes
0 answers

Practical game animation?

I understand that game development involves a 'game loop', in which the scene is drawn. This game loop either runs as fast as possible (no timer, frame animation) or is called based on a timer (timer animation). I'm curious as to how advanced…
Prime
  • 4,081
  • 9
  • 47
  • 64
0
votes
1 answer

Issue Switching Players - Tic Tac Toe

I have an issue where I can't seem to switch players (from X to O) correctly, it just switches randomly between the two. Here is my code so far: #include #include #include using namespace std; bool gameover =…
Mars_1996
  • 13
  • 1
0
votes
1 answer

JS / Canvas - How do I update the draw() function only when key is pressed?

edit : solved it myself, pretty sure it's not the ideal way to do it ( :D ) but it works for now :P solution : document.addEventListener('keydown', e => { switch (e.keyCode) { case 37: game.toggleTurn(); gameLoop(); break; …
user12146567
0
votes
0 answers

Java JPanel default double buffering doesn't seem to get rid of Choppy movement

I've been working on a simple 2D Java game to improve my coding skills. I've read that by default JPanel will be double buffered and so I thought I shouldn't have any problems with choppy movement if i just used a JPanel as my "Canvas".…
0
votes
1 answer

Why use a while loop for a game loop?

Just wondering, is there a specific reason to use a while loop as the game loop. Or could I use another method, like this one. Note: this is not proper code, and has not been tested. This is just a general idea. This example is also not consistent…
SwiftNinjaPro
  • 117
  • 1
  • 7