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

Separate game loops for rendering and updating without built-in timers or separate threads

I am wondering if there is a way to update two different operations (in this case, updating and rendering) within a single thread / loop. In my current scenario I have a TPS (ticks per second) that I want to have set to 64, and FPS (frames per…
Joseph
  • 127
  • 2
  • 10
0
votes
2 answers

Java2D game stutters randomly. What am I doing wrong?

I am currently developing a 2D game using Swing components. Each time I run my game it stutters randomly at some points. This is my game loop code: public class FixedTSGameLoop implements Runnable { private MapPanel _gamePanel; public…
Ido Sofi
  • 5
  • 3
0
votes
2 answers

changing value in gameloop

I have a variable tail. I set a value for this variable when creating constructor. And I have a changeTail() method which changes tail periodically by 10 pixels (increases 10 pixels and then decreases 10 pixels). This method is called in update…
0
votes
1 answer

Framerate capping in a fixed timestep game loop - Java

I am currently working on a Java 2D based game, and this is my current tutorial-based game loop: public class FixedTSGameLoop implements Runnable { private MapPanel _gamePanel; public FixedTSGameLoop(MapPanel panel) { this._gamePanel =…
Ido Sofi
  • 5
  • 3
0
votes
1 answer

Game too slow on Oreo

I'm new in Android and I'm trying to write a simple game. This is the Main Thread game loop (very simple) that I use (I don't know if is this the problem): @Override public void run(){ [...] while(running) { …
Calaf
  • 1,133
  • 2
  • 9
  • 22
0
votes
1 answer

canvas is black after restart or debugg while running

When I restart my App, I mean when I press the Homebutton and start it from the Task window, or when I debug it while it is still runnning the whole screen went black! This is my MainView: package net.kex.toll; import…
0
votes
0 answers

Anybody have idea about javafx turn-based game loop and event handling?

I've been doing turn-based battle game that wait for user response before doing action. So the game loop must be depends on opponent's health or our health not on frame rate. Is anyone have any idea about this. Because I did something like…
Pakanon Pantisawat
  • 115
  • 1
  • 2
  • 9
0
votes
1 answer

Game Refresh on Javascript Canvas Issue glitchy/flashing, using SetInterval

Need help with Canvas refresh, very glitchy and flashing, and im using setInterval. Dont know how to use requestanimation frame, any help is great //initiates entire game function fullLoader() { setInterval(drawPoke, fps); …
0
votes
1 answer

while loop preventing my listeners to work

okay, so I'm working on a boardgame. The first 'while loop' checks if the game is over, the inner 'while loop' is supposed to wait for the user input (squareSelector and rooSelector are my mouselisteners, 'k' and 's' are the input that are supposed…
0
votes
1 answer

Java- Check for key presses not using KeyListener

I'm making a prototype for a videogame using Java (I plan on porting it to Unity later, but since I'm pretty comfortable with Java, I figure it'll be quicker to get an idea for the structure and basic components of my game in Java). Perhaps…
David Lalo
  • 155
  • 7
0
votes
2 answers

Python loop behaving strangely

I've been tasked to code a simple guessing game for a school project, but cannot seem to figure out how to get the loops to work correctly. Essentially, the game is letting me replay it as many times as I want (so long as I guess the correct…
0
votes
1 answer

How can I limit the CPU usage?

How do I limit the CPU usage using this code for my Java game? I think one way might be to use Thread.sleep() but only if I can calculate the time or something like that. Can someone please help me? public void run(){ this.requestFocus(); …
0
votes
1 answer

Game loop with interpolation - weird step back

I have read about an interpolation applied to game loops and tried to implement it myself. It looks almost same as I expected, but when the object ends its movement weird step back takes place. I decided to paste here full source, because this…
0
votes
1 answer

Creating class object in the game loop

I'm wondering how is the proper way to create objects of classes in the game loop once? For example I've Box, Sphere, Cyllinder classes and I want to create several objects at different time while the program is running and work with them in the…
javierMarquez
  • 142
  • 2
  • 10
0
votes
1 answer

Core game logic loop to send data to channels in Netty

I want to send world state every 100 msec to all channels. But it calls only once. My code: public class IncomeMessageTcpHandler extends SimpleChannelInboundHandler { @Override public void channelActive(ChannelHandlerContext…
Dimmduh
  • 803
  • 1
  • 11
  • 18