<< Chapter < Page Chapter >> Page >

Run the program

I encourage you to copy the code from Listing 8 . 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.


In this module, you learned how to use objects of the SpriteSheet class and the Animation class to perform simple sprite sheet animation.

What's next?

In the next module, you will learn how to use objects of the SpriteSheet class and the Animation class to perform more complex sprite sheet animations than was the case in this module.


This section contains a variety of miscellaneous information.

Housekeeping material
  • Module name: Slick0180: Sprite sheet animation, part 1
  • File: Slick0180.htm
  • Published: 02/05/13
  • Revised: 06/08/15 for 64-bit

Financial : Although the Connexions site makes it possible for you to download a PDF file for thismodule at no charge, and also makes it possible for you to purchase a pre-printed version of the PDF file, you should beaware that some of the HTML elements in this module may not translate well into PDF.

I also want you to know that, I receive no financial compensation from the Connexions website even if you purchase the PDF version of the module.

In the past, unknown individuals have copied my modules from cnx.org, converted them to Kindle books, and placed them for sale on Amazon.com showing me as the author. Ineither receive compensation for those sales nor do I know who does receive compensation. If you purchase such a book, please beaware that it is a copy of a module that is freely available on cnx.org and that it was made and published withoutmy prior knowledge.

Affiliation : I am a professor of Computer Information Technology at Austin Community College in Austin, TX.

Complete program listing

A complete listing of the program discussed in this module is provided in Listing 8 .

Listing 8 . Source code for Slick0180 .
/*Slick0180.java Copyright 2013, R.G.BaldwinUses one row of sprites from a sprite sheet along with an Animation object to draw an animation of a dog playing.By default, the program displays one cycle of five sprites per second. Clock time is displayed below theanimation. The time that each image of the dog is displayed isindependent of the frame rate. Demonstrate this by changing the value of targetDelta and observing therelationship between the animation times and the clock. For best results, keep the targetDelta less than thedisplay time for each sprite (duration). Tested using JDK 1.7 under WinXP*********************************************************/ import org.newdawn.slick.AppGameContainer;import org.newdawn.slick.BasicGame; import org.newdawn.slick.GameContainer;import org.newdawn.slick.Graphics; import org.newdawn.slick.Image;import org.newdawn.slick.SlickException; import org.newdawn.slick.SpriteSheet;import org.newdawn.slick.Animation; import org.newdawn.slick.Color;public class Slick0180 extends BasicGame{ Image spriteSheetImage = null;float spriteSheetWidth; float spriteSheetHeight;int spritesPerRow = 5; int spritesPerColumn = 2;int targetDelta = 16;//msec int duration = 200;//time to display each spritelong totalTime = 0;//accumulate total time for display SpriteSheet spriteSheet;Animation animation; int spriteWidth;int spriteHeight; float spriteX = 0;//sprite drawing locationfloat spriteY = 0; //----------------------------------------------------//public Slick0180(){ //Call to superclass constructor is required.super("Slick0180, Baldwin."); }//end constructor//----------------------------------------------------// public static void main(String[]args) throws SlickException{AppGameContainer app = new AppGameContainer( new Slick0180(),450,120,false);app.start();//this statement is required }//end main//----------------------------------------------------// @Overridepublic void init(GameContainer gc) throwsSlickException { spriteSheetImage = new Image("Slick0180a1.png");//Enlarge the sprite sheet. Image temp = spriteSheetImage.getScaledCopy(580,224);spriteSheetImage = temp; spriteSheetWidth = spriteSheetImage.getWidth();spriteSheetHeight = spriteSheetImage.getHeight(); System.out.println("spriteSheetWidth: " + spriteSheetWidth); System.out.println("spriteSheetHeight: " + spriteSheetHeight); spriteWidth = (int)(spriteSheetWidth/spritesPerRow);spriteHeight = (int)(spriteSheetHeight/spritesPerColumn);//Instantiate a new spriteSheet object based on the // width and height of the tiles.spriteSheet = new SpriteSheet(spriteSheetImage, spriteWidth,spriteHeight); //Create a new animation based on a selection of// sprites from the sprite sheet. animation = new Animation(spriteSheet,0,//first column 0,//first row4,//last column 0,//last rowtrue,//horizontal duration,//display timetrue//autoupdate );gc.setShowFPS(true);//show FPS ////set frame rategc.setTargetFrameRate((int)(1000/targetDelta)); //set drawing locationspriteX = spriteWidth; spriteY = 0;}//end init //----------------------------------------------------//@Override public void update(GameContainer gc, int delta)throws SlickException{ //Note that the following is for clock time display// only. It does not effect the animation. totalTime += delta;//update total time accumulator}//end update //----------------------------------------------------//public void render(GameContainer gc, Graphics g) throws SlickException{g.setDrawMode(g.MODE_NORMAL); g.setBackground(Color.gray);//Draw the currently selected animation image at the // specified locationanimation.draw(spriteX,spriteY); g.drawString("totalTime = "+totalTime/1000,10f,100f);}//end render }//end class Slick0180//======================================================//


Questions & Answers

what is variations in raman spectra for nanomaterials
Jyoti Reply
I only see partial conversation and what's the question here!
Crow Reply
what about nanotechnology for water purification
RAW Reply
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
yes that's correct
I think
what is the stm
Brian Reply
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
How we are making nano material?
what is a peer
What is meant by 'nano scale'?
What is STMs full form?
scanning tunneling microscope
how nano science is used for hydrophobicity
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
what is differents between GO and RGO?
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
analytical skills graphene is prepared to kill any type viruses .
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
The nanotechnology is as new science, to scale nanometric
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
what school?
biomolecules are e building blocks of every organics and inorganic materials.
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
sciencedirect big data base
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!

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?