This page is optimized for mobile devices, if you would prefer the desktop version just click here

0.4 Slick0140: a first look at slick2d bitmap graphics  (Page 3/5)

Input images

This program uses two input images. An image file named background.jpg is used to create a background in the game window. Figure 1 shows what that image looks like when viewed in the Windows Paint program.

Figure 1 . Background image in Windows Paint.

The ladybug image

The second input image is a file named ladybug.png , which is a picture of a red and black ladybug on a transparent black background. Figure 2 shows this image when viewed in the Windows Paint program.

Figure 2 . Ladybug image in Windows Paint.

Figure 3 shows the same ladybug image when viewed in the Windows Picture and Fax Viewer program. Note that the black background from Figure 2 is transparent in Figure 3 .

Figure 3 . Ladybug image in Windows Picture and Fax Viewer.

Figure 4 shows the same ladybug image when viewed in the Gimp image editor program. This program provides even a different treatment for the transparent pixels.

Figure 4 . Ladybug image in Gimp.

The output image

Figure 5 shows a screen shot of the game window while the program is running

Figure 5 . Output from program Slick0140a.

Different drawing parameters

The same ladybug image is drawn three times in Figure 5 with different drawing parameters.

The leftmost image of the ladybug in Figure 5 is drawn with a scale factor of 0.75 and a drawing mode that honors transparency:MODE_NORMAL.

The center image of the ladybug in Figure 5 is drawn using a different approach with a scale factor of 1.0 and a drawing mode thathonors transparency: MODE_NORMAL.

The rightmost image of the ladybug in Figure 4 is drawn using the same approach as the leftmost image, a scale factor of 1.25, anda drawing mode that does not honor transparency: MODE_ALPHA_BLEND.

Are the mode names reversed?

As mentioned above, the two images of the ladybug with transparency were drawn using a Slick2D constant named MODE_NORMAL .

The image of the ladybug on the right without transparency was drawn using a Slick2D constant named MODE_ALPHA_BLEND .

These names seem to have been reversed. I would expect the constant with a name that includes the words alpha and blend to honor transparency but that doesn't seem to be the case.

Beginning of the class named Slick0140a

Listing 1 shows the beginning of the class named Slick0140a including some instance variable declarations and the constructor.

Listing 1 . Beginning of the class named Slick0140a.
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

The instance variables shown in Listing 1 and the values that they contain will be used later to display the three ladybugimages shown in Figure 5 .

<< Chapter < Page Page > Chapter >>

Read also:

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.
Jobilize.com uses cookies to ensure that you get the best experience. By continuing to use Jobilize.com web-site, you agree to the Terms of Use and Privacy Policy.