views:

81

answers:

3

When i play a video game (any old game like a racing game or pack man or whatever) how does everything get displayed on the screen in terms of what is going on in the program? is there some big RenderEverything method that is executed once a frame? this strikes me as a bit of a slow way to go about such a thing though.

EDIT: as a follow up question: How does the computer doing the rendering define the frame both for rendering graphis and for doing in game activites like having a character walk across a room slowly. Like is there some clock t that keeps increasing and every render and every movment hapens as a function of t? If so how is t defined relative to the system that it runs on?

I intend this question to be somewhat synonomous to: When my cursor in the screen right now blinks twice every second how does it know what a second is? Also in java how would i make a program that displays a line of text then waits a second and desplays another line? (perahps this is getting too spacific)

+1  A: 

They have a loop. Inside this loop it's called a method for rendering graphics and another for processing logic (and getting input). So this method will calculate everything based on the input and the graphics method print on screen based on the data already computed -- like what should be printed and its position.

Is that what you asked?

Questions about game development should be made here: http://gamedev.stackexchange.com/ :)

CrociDB
+1  A: 

When i play a video game (any old game like a racing game or pack man or whatever) how does everything get displayed on the screen in terms of what is going on in the program? is there some big RenderEverything method that is executed once a frame?

Depends on the game. 2D games may be able to keep part of scenes rendered in previous frames, especially old games without scrolling screens. 3D game most likely redraws entire screen. Also good game never renders everything - only visible objects. Because rendering everything is slow, while rendering only visible objects is significantly faster.

this strikes me as a bit of a slow way to go about such a thing though.

You are free to try to find different way. Normal game repaints every visible object. Non-hardware-accelerated game may track unmodified screen regions, and repaint only objects that changed, moved, etc. Hardware accelerated game doesn't have to do that - it can redraw everything on screen every frame. As game/frame/scene complexity increases, it is much easier to simply repaint every visible object during every frame instead of tracking things that changed from previous frame.

SigTerm
A: 

That's basically it. The 'video game' is effectively a big state machine where all state is updated according to a frame rate. User input combined with game rules and enemy AI affect the state of the game. Once every frame the players view of the game, not the complete view of the game, is rendered.

Download the quake source, it makes for some interesting reading in the comments and also gives excellent insight as to how a game is constructed.

Adrian Regan
what is quake? Is that a game?
David
Wiki it or idSoftware. Thanks, now I feel like an auld fella :-)
Adrian Regan
@David: "what is quake". Well, it is one of the first fully 3d games for PC (if you don't mind descent, that is). Made in 1996 by idsoftware, still available for purchase. http://en.wikipedia.org/wiki/Quake_(video_game) . If you haven't even heard about it, you should be probably ashamed.
SigTerm