<< Chapter < Page Chapter >> Page >
Listing 6 . The main method.
public static void main(String[] args)throws SlickException{ try{AppGameContainer app = ( new AppGameContainer(new Slick0130a(),400,200,false)); app.start();}catch(SlickException e){ e.printStackTrace();}//end catch }//end main

A different constructor

Listing 6 calls a different overloaded constructor for the AppGameContainer class than I have used in earlier modules.

This version of the constructor allows for setting the width and height of the game window. In this case, the game window is set to a width of 400 pixelsand a height of 200 pixels as shown in Figure 1 .

The last parameter to this constructor is described as a boolean parameter that allows for the selection of a full-screen game window. As of thiswriting, I have been unable to get this to work. When I set the third parameter to true, I get a compiler error. However, I haven't spent any time investigatingwhat I might be doing wrong.

The overridden init method

The overridden init method is shown in Listing 7 .

Listing 7 . The overridden init method.
public void init(GameContainer gc) throws SlickException {//Set the frame rate in frames per second. gc.setTargetFrameRate(2);}//end init

Set the target frame rate

Listing 7 calls the setTargetFrameRate on the GameContainer object passing 2 as a parameter. The description of this method in the javadocs is "Set the target fps we're hoping to get,"

The overridden update method

Listing 8 shows the overridden update method.

Listing 8 . The overridden update method.
public void update(GameContainer gc, int delta) throws SlickException{//Compute and save total time since start in seconds. totalTime += delta/1000.0;//Save delta for display in render method.incrementalTime = delta;}//end update

Compute total elapsed time

Listing 8 converts the incoming value of delta in milliseconds into seconds and adds it to the value stored in the instancevariable named totalTime that is declared in Listing 5 . The totalTime value will be used to display the first line of text near the center of Figure 1 .

Save the value of delta

Listing 8 saves the incoming value of delta in the instance variable named i ncrementalTime that was also declared in Listing 5 . The value stored in incrementalTime will be used to display the second line of text near the center of Figure 1 .

The overridden render method

Listing 9 shows the overridden render method.

Listing 9 . The overridden render method.
public void render(GameContainer gc, Graphics g) throws SlickException{//Truncate totalTime to one decimal digit and // displaydouble time = (int)(totalTime*10)/10.0; g.drawString("totalTime: "+time,100.0f,100.0f);//Display incremental time.g.drawString("incrementalTime: " + incrementalTime, 100.0f,120.0f);}//end render

Truncate and draw the total time

Listing 9 begins by truncating the value of totalTime to only two decimal digits and saving the truncated value in a local variable named time . I will leave it as an exercise for the student to analyze the code that I used todo that.

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