<< 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

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 to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
characteristics of micro business
for teaching engĺish at school how nano technology help us
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
what is the actual application of fullerenes nowadays?
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
is Bucky paper clear?
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
so some one know about replacing silicon atom with phosphorous in semiconductors device?
s. Reply
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Do you know which machine is used to that process?
how to fabricate graphene ink ?
for screen printed electrodes ?
What is lattice structure?
s. Reply
of graphene you mean?
or in general
in general
Graphene has a hexagonal structure
On having this app for quite a bit time, Haven't realised there's a chat room in it.
what is biological synthesis of nanoparticles
Sanket Reply
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?