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
1 answer

SFML Won't Draw Anything?

I'm used to using SDL for C++ but I heard that SFML is better so I tried it. I tried to render a basic sprite and that didn't work. Then I tried to clear the window to a different colour and that didn't work. It's simple code so what is going on?…
MagnusCaligo
  • 707
  • 2
  • 8
  • 28
0
votes
2 answers

How to use the repaint() method with a game loop

I'm trying to learn how to create a game loop with java and draw a new screen a certain amount of times per second. The game loop is working fine but when I try to call the paint method with repaint() the paint method is not called. Here is my…
Priyank
  • 49
  • 1
  • 2
  • 6
0
votes
1 answer

How to pause and resume GameLoop?

I have problem with resuming my game after pause. I'm using SurfaceView, and here is the most important part of code: void pause() { if (!pause) { gameLoopThread.setRunning(false); pause = !pause; …
pjp
  • 157
  • 1
  • 12
0
votes
1 answer

Python/Pygame Trouble with Game loop/Getting code to run

For the past few days I've been working on this code for pong and I've almost got it running. Everything works up to the movement of the objects. The screen just freezes when the pygame window opens. There seems to be something wrong in my main()…
Justin Farr
  • 183
  • 3
  • 5
  • 16
0
votes
1 answer

al_draw_filled_rectangle() seems to work only in some classes

I am trying to write a basic program with a game loop (it can't be called a game any time soon). Almost everything I have (which isn't much, frankly) is fine, just the one object in my render tree doesn't render! The game loop: void…
11684
  • 7,356
  • 12
  • 48
  • 71
0
votes
2 answers

Rotating a point around another point in a game loop (Java)

I'm trying to create a method which rotates a point around another point in Java for a Asteroids clone that I want to make.Right now I have 2 Point instances called point and center.The code for my method is this: public void Rotate(double angle){ …
Paul Iancu
  • 19
  • 1
0
votes
1 answer

Is clojure.core.async appropriate for syncing game state and user input over WebSockets? (loop runs once/100ms)

I have a small Clojure game (think Snake but multiplayer; if you hit another snake, you lose) running over WebSockets - logic is in the Clojure backend, rendering is in the browser. Every "turn" of the game takes 100ms, during which the game steps,…
quantumtremor
  • 3,787
  • 2
  • 17
  • 20
0
votes
0 answers

JavaFX gameloop without Timeline

I want to write a game engine with JavaFX. In my current tests I am using a javafx.animation.Timeline as my gameloop. The thing I don't like about the Timeline is that if the rendering process takes longer than the time between frames, the Timeline…
Quijx
  • 366
  • 1
  • 10
0
votes
0 answers

Do some devices have not the correct time

I am developing a Snake game. On all of my devices I have the same speed. Except my Nexus 7. The game just runs slower. I use System.currenttimemillis() to count the time for the loop (f.E. 100ms) and get the time how long everything takes to have…
Nick
  • 135
  • 1
  • 4
  • 13
0
votes
1 answer

TextArea with Canvas Binding to Rect

I have the problem of this textarea not showing up when I run it. Is there any way to make it show up. BTW its getting called through the gameloop on a class that extends canvas. public void render(Graphics g){ Graphics2D g2d = (Graphics2D) g; …
0
votes
1 answer

Player moves faster with higher deltaTime

Here's the first version, where I have a delta of 1/60: http://jsfiddle.net/ocdrd0uy/ Here's the second version, where the only thing I changed was the delta to 1/20: http://jsfiddle.net/ocdrd0uy/1/ var delta = 1 / 60; --> var delta = 1 / 20; I…
user2039981
0
votes
1 answer

How to interpolate collisions between paint events

As of late, I have been researching all sorts of fancy collision detection algorithms and quadtrees for a 2 dimensional app, and have my application at the point where I want to start implementing those collision algorithms in. My gameloop is…
Bennett Yeo
  • 819
  • 2
  • 14
  • 28
0
votes
0 answers

Main Menu for 2d game in ALLEGRO5

I've big problem with my university project. I tried to make simple game in Allegro5, but I've stopped at making Main Menu. I've basic code, but on 4 possibility: Start Game, Options, Credits,Exit. I can see just one of them ( exit ). Don't know how…
0
votes
1 answer

Game Loop - Time Computation

In my Opengl "Engine" i have the following method to compute all the time values, i could need in a frame: public static void computeTime(){ thisFrame = System.nanoTime(); delta = thisFrame - lastFrame; lastFrame = thisFrame; deltams…
T_01
  • 1,256
  • 3
  • 16
  • 35
0
votes
4 answers

Why do I keep getting Java.Lang.NullPointerException

I keep getting a Java.Lang.NullPointerException on this code: private void render(){ BufferStrategy bs = this.getBufferStrategy(); if(bs == null){ this.createBufferStrategy(3); } Graphics g = bs.getDrawGraphics(); …
swingBoris
  • 35
  • 6