<< Chapter < Page Chapter >> Page >

What is delta?

An int parameter named delta is received by the update method shown in Listing 6 . (The update method s a concrete version of the method having the same signature that is declared in the Game interface.)

According to the documentation for the update method in the Game interface, delta is

"The amount of time that has passed since last update in milliseconds"

Having that time available can be valuable in some game programs. For example, you might like for one of the actors to light a fuse on a bomb and havethat bomb detonate some given number of milliseconds later. In that case, the program would need real time information to know when to detonate the bomb.

Listing 5 shows the source code for the getDelta method.

Listing 5 . The getDelta method of the GameContainer class.
protected int getDelta() { long time = getTime();int delta = (int) (time - lastFrame); lastFrame = time;return delta;}//end getDelta method

Without getting into the details, the method named getTime that is called in Listing 5 returns the amount of time, (with a resolution of one millisecond) , that has elapsed since a historical point in time before the game started running.

The GameContainer class contains a protected instance variable of type long named lastFrame that is used to store a time value.

The code in Listing 5

  • subtracts the time value stored in lastFrame from the current time,
  • converts the time difference to type int , saving it in delta , and
  • stores the current time in lastFrame .

The difference between the two time values represents a time interval and that difference is returned as type int .

Various methods in the AppGameContainer and GameContainer classes call the getDelta method in such a way that the value of delta represents the time required to update and renderone frame when the program is running. (There are some other options as well that I may discuss in a future module.)

When the method named update is called in Listing 6 , the incoming parameter named delta contains the number of milliseconds that have elapsed since the last time that the update method was called.

When the method named getDelta is called in Listing 2 , the return value is discarded. This suggests that the call to the getDelta method in Listing 2 is made simply to cause the variable named lastFrame to be initialized with time that the start method was called.

The gameLoop method of the AppGameContainer class

That leaves us with one more method call from Listing 2 that we need to examine -- gameLoop . I anticipate that will be a fairly long discussion, so I am going to defer that discussion until the nextmodule.

Run the program

As explained earlier, the skeleton code in Listing 6 is different from the skeleton code that I presented in earlier modules.Therefore, I encourage you to copy the code from Listing 6 . Compile the code and execute it,making changes, and observing the results of your changes. Make certain that you can explain why your changes behave as they do.

Summary

The main purpose of this module was to analyze the behavior of the Slick2D gameengine when you call the start method to cause a Slick2D game program to start running.

Questions & Answers

what is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
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
cell is the building block of life.
Condoleezza 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