Game Development Reference
In addition to these managers are game objects. Game objects represent all
the assets placed in a game environment. These include the terrain, sky, trees,
weapons, rocks, nonplayer characters, rain, explosions, and so on. Because game
objects represent a very diverse set of elements, they can also be customized
through the addition of components that may include elements of Artificial
Intelligence (AI), sound, graphics, and physics. The AI component determines
how a game object will behave. For example, a rock in a scene would not have an
AI component, but an enemy computer-controlled character would have AI to
control how it attacks and pursues the player. A sound component gives a game
object a sound. For example, an explosion would have a sound component
whereas a tree may not. The physics component allows a game object to act
within the physics system of the game. For example, physics added to a rock
would see it roll down a hill or bounce and break apart when it falls. The graphics
component dictates how the game object is drawn. This is the way in which
it is presented to players on the screen. Some game objects will be visible and
some will not. For example, a tree in a scene is a visible game object, whereas
an autosave checkpoint, which may be a location in a game level, is not.
1.4.2 The Main Loop
All games run in the same way, as illustrated in Figure 1.17 . There is
an initialization stage in which computer memory is allocated, saved
information is retrieved, and graphics and peripheral devices are checked.
This is followed by the main game loop or main loop . The main loop runs
continuously over and over again until the player decides to quit the game.
While in the main loop the game executes a cycle of functions that processes
user input messages; checks through all game objects and updates their
state, including their position; updates the environment with respect to
game object positions, user interaction, and the physics system; and finally
renders the new scene to the screen.
Essentially each loop renders one frame of graphics on the screen. The faster the
loop executes, the smoother the animation of the game appears. The more
processing that needs to be performed during the main loop, the slower it will
execute. As the number of game objects increases, the amount of work the
main loop has to do also increases and therefore slows down the time between
frames being rendered on the screen. This time is called frames per second (FPS).
Game developers strive for very high FPS, and for today's computers and
consoles, FPS can extend beyond 600. In some circumstances, however,
such as on mobile devices with less processing power, FPS can become
very low with only several game objects, and the animation will flicker
and user controls are nonresponsive. Having said this, beginner game
developers need to be aware of this issue as even on a very powerful
computer, adding a lot of highly detailed game objects can soon bring the
FPS to a grinding halt. Anything below 25 FPS is considered unacceptable,
and as it approaches 15 FPS the animation starts to flicker.