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

Summary

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.

Miscellaneous

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

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

-end-

Questions & Answers

Application of nanotechnology in medicine
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.
Damian
yes that's correct
Professor
I think
Professor
what is the stm
Brian Reply
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
Rafiq
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
Damian
How we are making nano material?
LITNING Reply
what is a peer
LITNING Reply
What is meant by 'nano scale'?
LITNING Reply
What is STMs full form?
LITNING
scanning tunneling microscope
Sahil
how nano science is used for hydrophobicity
Santosh
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
Rafiq
what is differents between GO and RGO?
Mahi
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
Rafiq
if virus is killing to make ARTIFICIAL DNA OF GRAPHENE FOR KILLED THE VIRUS .THIS IS OUR ASSUMPTION
Anam
analytical skills graphene is prepared to kill any type viruses .
Anam
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
Bob
The nanotechnology is as new science, to scale nanometric
brayan
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Damian
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
Renato
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
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
Adin
why?
Adin
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
research.net
kanaga
sciencedirect big data base
Ernesto
Introduction about quantum dots in nanotechnology
Praveena Reply
hi
Loga
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
Bharti
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?

Ask