<< Chapter < Page Chapter >> Page >

Draw the rightmost ladybug

After that, Listing 4 calls the setDrawMode method on the incoming Graphics parameter to set the drawing mode to MODE_ALPHA_BLEND and calls the same draw method of the ladybug Image object to draw the rightmost ladybug in Figure 5 .

Note that this drawing of the ladybug image does not honor transparent pixels.

Call the drawImage method of the Graphics class

Finally, Listing 4 calls the setDrawMode method on the incoming Graphics parameter to set the drawing mode back to MODE_NORMAL and then calls the drawImage method on the incoming Graphics parameter to draw the middle ladybug in Figure 5 . (This approach is similar to the approach that would be used to draw an image using the standard edition Java library.)

Note that the reference to the ladybug Image object and the drawing coordinates are passed as parameters to the drawImage method. Some of the overloaded drawImage methods provide scaling. However, there is no scale parameter for this version of the drawImage method so the ladybug was drawn at actual size.

Many overloaded drawing methods

There are many overloaded versions of the draw and the drawImage methods.

That completes the discussion of the program named Slick0140a .

Run the program

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


You learned that while there are many classes, interfaces, and methods in the Slick2D library with names that match classes, interfaces, and methods in thestandard edition Java library, they are not the same.

You learned that you can access the Slick2D documentation at (External Link) . (A copy of the documentation is also included in the distribution zip file.)

You learned how to set the drawing mode so that bitmap images drawn in the game window will either honor or not honor transparent pixels.

You learned how to draw bitmap images in the game window using both the draw methods of the Image class and the drawImage methods of the Graphics class.

What's next?

In the next module, you will learn how to make sprites move at a constant speed in front of an image in the face of a widely varying frame rate. You willalso learn about a rudimentary form of collision detection.


This section contains a variety of miscellaneous information.

Housekeeping material
  • Module name: Slick0140: A first look at Slick2D bitmap graphics
  • File: Slick0140.htm
  • Published: 02/04/13
  • Revised: 06/09/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

Listing 5 contains a complete listing of the program named Slick0140a .

Listing 5 . Source code for the program named Slick0140a.
/*Slick0140a.java Copyright 2012, R.G.BaldwinIllustrates drawing a sprite image with transparent parts on a background image using two differentapproaches. 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;public class Slick0140a extends BasicGame{ Image ladybug = null;Image background = null; float leftX = 100;//leftmost position of ladybugfloat leftY = 100;float middleX = 200;//middle position of ladybug float middleY = 50;float rightX = 300;//rightmost position of ladybugfloat rightY = 100;float leftScale = 0.75f;//drawing scale factorsfloat rightScale = 1.25f; //----------------------------------------------------//public Slick0140a(){//constructor //Set the titlesuper("Slick0140a, baldwin"); }//end constructor//----------------------------------------------------// public static void main(String[]args) throws SlickException{AppGameContainer app = new AppGameContainer( new Slick0140a(),414,307,false);app.start(); }//end main//----------------------------------------------------// @Overridepublic void init(GameContainer gc) throws SlickException {ladybug = new Image("ladybug.png"); background = new Image("background.jpg");gc.setShowFPS(false);//disable FPS display gc.setTargetFrameRate(60);//set frame rate}//end init //----------------------------------------------------//@Override public void update(GameContainer gc, int delta)throws SlickException{ //No updates required in this program.}//end update //----------------------------------------------------//public void render(GameContainer gc, Graphics g) throws SlickException{//Note that the names of the drawMode constants seem // to be backwards.//Draw the background and two versions of the// ladybug by calling a draw method of the Image // class.g.setDrawMode(g.MODE_NORMAL);//honors transparency background.draw(0,0);ladybug.draw(leftX,leftY,leftScale); g.setDrawMode(g.MODE_ALPHA_BLEND);//no transparencyladybug.draw(rightX,rightY,rightScale);//Draw a third version of the ladybug by calling // a drawImage method of the Graphics class.g.setDrawMode(g.MODE_NORMAL); g.drawImage(ladybug,middleX,middleY);}//end render }//end class Slick0140a


Questions & Answers

how can chip be made from sand
Eke Reply
is this allso about nanoscale material
are nano particles real
Missy Reply
Hello, if I study Physics teacher in bachelor, can I study Nanotechnology in master?
Lale Reply
no can't
where is the latest information on a no technology how can I find it
where we get a research paper on Nano chemistry....?
Maira Reply
nanopartical of organic/inorganic / physical chemistry , pdf / thesis / review
what are the products of Nano chemistry?
Maira Reply
There are lots of products of nano chemistry... Like nano coatings.....carbon fiber.. And lots of others..
Even nanotechnology is pretty much all about chemistry... Its the chemistry on quantum or atomic level
no nanotechnology is also a part of physics and maths it requires angle formulas and some pressure regarding concepts
Preparation and Applications of Nanomaterial for Drug Delivery
Hafiz Reply
Application of nanotechnology in medicine
has a lot of application modern world
what is variations in raman spectra for nanomaterials
Jyoti Reply
ya I also want to know the raman spectra
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
Nasa has use it in the 60's, copper as water purification in the moon travel.
nanocopper obvius
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 .
Any one who tell me about Preparation and application of Nanomaterial for drug Delivery
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
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 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?