<< Chapter < Page Chapter >> Page >

General background information

As you learned in the previous module, the start method (see Listing 1 ) calls the setup method and then calls the getDelta method. Following that, it calls the gameLoop method as described below.

The property named running

The GameContainer class declares a protected boolean variable named running , which is inherited into the object of the AppGameContainer class. The descriptive comment reads "True if we're currently running the game loop."

The initial value of this variable is true and as near as I can tell, it only goes false

  • when the exit method is called,
  • when the closeRequested method is called and returns true, or
  • when some code in the game throws a SlickException .

Calling the gameLoop method

The start method in Listing 1 shows a call to the gameLoop method inside a while loop with a call to the running method as theconditional clause.

Listing 1 . The start method of the AppGameContainer class.
public void start() throws SlickException { try {setup();getDelta(); while (running()) {gameLoop(); }} finally { destroy();}if (forceExit) { System.exit(0);} }//end start

As you can see in Listing 1 , the gameLoop method is called repeatedly while the variable named running is true. Each time it returns, it is called again.

I will refer to each call to the gameLoop method as one iteration of the game loop in the discussion that follows.

The gameLoop method

The gameLoop method of the AppGameContainer class is shown in Listing 2 .

Listing 2 . The gameLoop method of the AppGameContainer class.
protected void gameLoop() throws SlickException { int delta = getDelta();if (!Display.isVisible()&&updateOnlyOnVisible) { try { Thread.sleep(100); } catch (Exception e) {}} else { try {updateAndRender(delta); } catch (SlickException e) {Log.error(e); running = false;return; }//end catch}//end else updateFPS();Display.update();if (Display.isCloseRequested()) { if (game.closeRequested()) {running = false; }//end if}//end if }//end gameLoop method

A verbal description

This is my verbal description of what happens each time the start method calls the gameLoop method.

First the gameLoop method gets the value for delta (the elapsed time since the call to the gameLoop method during the previous iteration of the game loop) .

If the display (the game window) is not visible and a property named updateOnlyOnVisible is true, the gameLoop method takes appropriate action. I will leave it as an exercise forinterested students to analyze those actions. (The program goes to sleep for 100 milliseconds.)

If the display is visible, the gameLoop method calls the updateAndRender method of the GameContainer class passing delta as a parameter. Upon return, the gameLoop method performs some housekeeping tasks and terminates.

The updateAndRender method

Listing 3 shows the beginning of the updateAndRender method of the GameContainer class. This is the code that controls calls to the update method. The code that controls calls to the render method is shown in Listing 4 later.

Questions & Answers

what is phylogeny
Odigie Reply
evolutionary history and relationship of an organism or group of organisms
AI-Robot
ok
Deng
what is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
cell is the smallest unit of the humanity biologically
Abraham
what is biology
Victoria Reply
what is biology
Abraham
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
Biology is a branch of Natural science which deals/About living Organism.
Ahmedin Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Anatomy of a game engine. OpenStax CNX. Feb 07, 2013 Download for free at https://legacy.cnx.org/content/col11489/1.13
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Anatomy of a game engine' conversation and receive update notifications?

Ask