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
-1
votes
3 answers

Game Loop updates too fast

I want to create a start menue for a Pong clone where the ball in the background bounces off the edges. However the game loop updates to fast so the Coordinates of the ball are already out of the JFrame before you can see it and it moves to fast. I…
Nicky
  • 121
  • 1
  • 7
-1
votes
1 answer

Rails Game Loop in Application Controller?

Since i'm writing a game in RoR, i need to have a game loop that is responsible for checking different things every time a page refresh happens. My question is, what is the best way to implement ? I currently include the game_loop in my application…
Spyros
  • 46,820
  • 25
  • 86
  • 129
-1
votes
1 answer

How to get the clicks coordinates python 3

I am making a cross-zero game on python 3.5.4 with tkinter. I have made this at the moment: from sys import * from tkinter import * screen = Tk() c = Canvas(width=600, height=600) c.pack() Line1 = c.create_line(200, 0, 200, 600) Line2 =…
user9983006
-1
votes
2 answers

C# console App - gameloop / multiple object

as the title says im currently working on a Console Game in c#. The problem is, i fail to make a working gameloop everytime... Also I have a Problem with "spawning" multiple objects like in this case bullets or enemys (Im still new to c# and also…
atzaka
  • 3
  • 6
-1
votes
1 answer

Can I check for events with SDL without using an embedded while_loop?

I originally wrote my game using glfw. However due to it lack of android portability I have to replace all of my glfw code with SDL, since SDL is more portable. My original game loop using the glfw frame work was very striaghtforward. Here it is: //…
MagnusHimmler
  • 65
  • 2
  • 7
-1
votes
1 answer

How should I figure out what my update length (delta) should be in my Game loop in Java?

Consider this Game Loop: double nextTime = (double)System.nanoTime() / 1000000000.0; while(runFlag) { double currTime = (double)System.nanoTime() / 1000000000.0; if(currTime >= nextTime) { …
imgolden62
  • 396
  • 2
  • 5
  • 14
-1
votes
2 answers

System.out.println printing twice in each iteration of while loop

I am trying to figure out why I am getting two lines printed with each iteration of the while loop when I run this code: public void run() { long currentTime = System.nanoTime(); long targetFPS = 1000; long delta; …
-1
votes
1 answer

How do you use the 'system' command in C++?

I'm exploring C++ and trying to make a simple loop that will clear screen. I know in C, the 'system' command syntax: system("cls"); will make the command terminal clear the screen. Here is the code: #include using namespace…
-1
votes
1 answer

Writing an efficient game-loop

I have recently asked a question here about programming a game so it will be efficient and won't lag. I have made a game that lags like hell. I suspect that the way that I programmed it's game-loop, could be the source of the problem. I want to…
user3150201
  • 1,901
  • 5
  • 26
  • 29
-1
votes
3 answers

game-loop stops and waits for the user

I was making this game on c++ in which coins keep on increasing and user can decide what to do with them, however the game stops for the user to enter the command. What i want is that coins keep on stacking up and if the user wishes to do something…
Armaan
  • 9
  • 3
-1
votes
2 answers

Trying to understand an advanced game loop in Java

I'm working on a simple Java 2D game. I wrote a certain game-loop for the game. Using this game-loop, the game sometimes runs in moderate (constant, I think) speed, and sometimes when I start it, it runs in slow (constant) speed. I learned to…
Josh
  • 95
  • 1
  • 9
-1
votes
1 answer

Adding an image to frame, not in center, but should be.. + game programming in general

I just started learning game programming, after taking a 1 semester course in the university, so i think im ready and i really want to do this, so first of all: 1) What could be good resources for learning? Ive googlef a lot and have two books:…
MustSeeMelons
  • 737
  • 1
  • 10
  • 24
-1
votes
1 answer

Restarting a game

I am creating a simple game of TicTacToe, but I got stuck in restarting the game whenever the game ends and when I click the restart button. I just did the first horizontal buttons. When you press them a window will pop-up and tell you that there is…
ickyrr
  • 1,963
  • 1
  • 14
  • 14
-2
votes
1 answer

How do I loop the paint event in Windows Forms to create a simple game loop?

I'm attempting to create a simple snake game in C# visual studio as an exercise. I have very little knowledge of the Windows Forms App, but it seemed like the easiest way to access drawing and user input with the arrows. Is this a good framework to…
duffin01
  • 11
  • 3
-2
votes
2 answers

What does date.now() 'then' does here? - Javascript

I've used this tutorial to help me out writing a simple JS game for my school assignment. However I am now looking at the gameloop and I have no clue how this particular function is working. Here is the URL of the tutorial. The block of code you're…
Melvin
  • 27
  • 6
1 2 3
32
33