The central code loop responsible for handling the running gameplay. At its most basic state, it accepts input, resolves the actions of entities, and renders the scene.

learn more… | top users | synonyms (1)

16
votes
4answers
2k views

Should actors in a game be responsible for drawing themselves?

I am very new to game development, but not to programming. I am (again) playing around with a Pong type game using JavaScript's canvas element. I have created a Paddle object which has the following ...
80
votes
3answers
22k views

Tips for writing the main game loop? [closed]

Can anyone recommend some good tips, articles, sites, etc. for writing the main game loop? What are some things that you should do in the game loop, and what are some things that you shouldn't do in ...
27
votes
3answers
2k views

Several classes need to access the same data, where should the data be declared?

I have a basic 2D tower defense game in C++. Each map is a separate class which inherits from GameState. The map delegates the logic and drawing code to each object in the game and sets data such as ...
11
votes
2answers
3k views

Semi-fixed or Fully-fixed timestep?

I am making an iphone shmup and am trying to decide what type of game loop to use. I want to use either semi-fixed timestep or fully-fixed timestep. With semi-fixed timestep I will make zero or more ...
22
votes
2answers
3k views

Is it safe to use Sleep() in game loop (on Windows)?

Is it safe to use Sleep() function on Windows in game loop (C++)? I want to have fixed frame rate.
19
votes
2answers
12k views

A good way to build a game loop in OpenGL

I'm currently beginning to learn OpenGL at school, and I've started making a simple game the other day (on my own, not for school). I'm using freeglut, and am building it in C, so for my game loop I ...
6
votes
1answer
1k views

How to chain actions/animations together and delay their execution?

I'm trying to build a simple game with a number of screens - 'TitleScreen', 'LoadingScreen', 'PlayScreen', 'HighScoreScreen' - each of which has it's own draw & update logic methods, sprites, ...
7
votes
2answers
499 views

Replay system: record inputs or events?

I read this: How to design a replay system But it don't really answer my question. My game is built with the client "view" of the game as a separate program from the server "model" and "controller". ...
12
votes
4answers
2k views

Programming the combat sequence in a role playing game

I'm trying to write a short "game" where a player goes around and fights monsters but I have no idea how to handle the combat. For example, say I have a "Warrior" and a "Troll". How do the two fight ...
4
votes
4answers
17k views

Android game scrolling background

I'm just trying to figure out the best approach for running a scolling background on an android device. The method I have so far.... its pretty laggy. I use threads, which I believe is not the best ...
16
votes
9answers
1k views

How do I best remove an entity from my game loop when it is dead?

Ok so I have a big list of all my entities which I loop through and update. In AS3 I can store this as an Array (dynamic length, untyped), a Vector (typed) or a linked list (not native). At the moment ...
13
votes
3answers
788 views

Game loop, how to check for conditions once, do something, then not do it again

For example, I have a Game class and it keeps an int that tracks the player's lives. I have a conditional if ( mLives < 1 ) { // Do some work. } However this condition keeps firing and the ...
7
votes
2answers
3k views

Server side game loop

Many java games use thread.sleep() to controll fps. Since the server does not display graphics, should the server game loop keep running just calculating delta time? Like this example: long ...
2
votes
2answers
970 views

Why does my game loop speed vary on different platforms with the same hardware?

I've got a serious issue with my game loop. This loop varies in time with the platform and with the same hardware. This is a list of FPS achieved: - Windows ======= 140 to 150 - Linux ...
1
vote
1answer
96 views

Implement an upper FPS limit in the gameloop

I implemented my game-loop as described in deWiTTER's article, using the last approach with an unlimited FPS and a constant game-speed. My problem is, that the unlimited FPS cranks up my CPU usage to ...
13
votes
2answers
1k views

Design of a turn-based game where actions have side-effects

I am writing a computer version of the game Dominion. It is a turn-based card game where action cards, treasure cards, and victory point cards are accumulated into a player's personal deck. I have the ...
12
votes
2answers
2k views

“Optimal” game loop for 2D side-scroller

Is it possible to describe an "optimal" (in terms of performance) layout for a 2D side-scroller's game loop? In this context the "game loop" takes user input, updates the states of game objects and ...
7
votes
2answers
2k views

Multi threaded game - updating, rendering, and how to split them

From the StackOverflow post (it was recommended I move this): So, I'm working on a game engine, and I've made pretty good progress. However, my engine is single-threaded, and the advantages of ...
15
votes
2answers
1k views

Where should collision detection logic be placed?

I am developing a small 2D game engine. The characters have a paint method which currently does the following: Calculate the new position of the character as per its speed, etc. Update the collision ...
11
votes
1answer
497 views

Behavior Trees :: Actions That Take Longer Than One Tick

From what I understand on Behavior Trees, each Behavior should be a short goal oriented Action that could be done in a few iterations. So for example, below is an image of a Behavior Tree: Now let ...
15
votes
3answers
4k views

Finite state machine in C++

So, I've read a lot about using FSMs to do game state management, things like what an FSM is, and using a stack or set of states for building one. I've gone through all that. But I'm stuck at writing ...
15
votes
5answers
901 views

Game actions that take multiple frames to complete

I've never really done much game programming before, pretty straightforward question. Imagine I'm building a Tetris game, with the main loop looking something like this. for every frame handle ...
4
votes
2answers
1k views

Correct order of operations in a platformer game loop

I've run into an issue with my Mega Man engine, and the structure of my game loop is making it very difficult to fix. With Rush Jet, or any falling platform, Mega Man needs to stay attached to the ...
7
votes
2answers
1k views

Java 2D game programming: Different approaches to make a game loop

I am new to Java game programming, but the more I read the more I'm confused, because I've seen several different approaches to make a game loop: 1. The standard approach, that uses the Timer class ...
2
votes
1answer
186 views

does order of updates and renders matter?

I know in a game loop there needs to be an order like physics should update before rendering. So, I have created two separate functions: update and render and the game loops like below: ...
1
vote
1answer
736 views

javascript game loop and game update design

There is a main game loop in my program, which calls game update every frame. However, to make better animation and better control, there is a need to implement a function like updateEveryNFrames(n, ...
-1
votes
3answers
2k views

C++ GameState management

I have been attempting to make a game engine in C++ and have come across the dilemma of game state management. I have done a lot of research and found numerous ways of accomplishing from game engine ...
2
votes
2answers
1k views

Turn-based Strategy Loop

I'm working on a strategy game. It's turn-based and card-based (think Dominion-style), done in a client, with eventual AI in the works. I've already implemented almost all of the game logic (methods ...
1
vote
1answer
739 views

CPU usage, game loop and sleep()

I've read about this topic on numerous discussion sites, but I can't seem to find a clear definitive (up-to-date) answer, and hopefully this will me some more insight: I've read the excellent game ...
1
vote
2answers
251 views

what is the best way to use loops to detect events while the main loop is running?

I am making an "game" that has pathfinding using pygame. I am using Astar algo. I have a main loop which draws the whole map. In the loop I check for events. If user press "enter" or "space", random ...
0
votes
1answer
676 views

In some games, we just let the main() loop be the Player object or Table object?

I was thinking that let's say if there is a game of Blackjack or MasterMind, then we should have a class called Dealer or ComputerPal, which is how the computer interact with us (as a dealer for ...
-3
votes
1answer
377 views

Options available to a programmer on the Main Game Loop [closed]

Could someone please give me some insight into each one of the four topics listed below. I have a good idea about what passive and active rendering are, and that the use of active rendering is more ...