|
Images in games programming / Alex Zak
You will have to add images to almost
every game you will write (except for the most simple games,
like the ping-pong I
made). Therefore, it is important to know about the different types of
images.
When you save an image with your image manipulation program, you
probably get a file that can not be displayed
with Java and other programming languages (for example, by default, my
program GIMP
produces unusable in Java .xcf files).
Java can read JPEG, GIF, PNG and some other file formats, so save your
images as one of those files. In this article I will
discuss those three types.
JPEG
This format is used on the web to display photographs, because it has a
good algorithm for gradation. However, it
poorly displays contrast colors, so that text and diagrams will look
bad. Also, JPEG has no support of transparency
at all, so I usually use JPEGS only to display background images, or
images that are rectangular.
GIF
GIF, unlike JPEG, shows contrasting colors well, so it can be used to
display images with text or diagrams. However, it
supports only a limited number of colors, so photographs or images with
color gradation will display poorly. GIF
supports transparency, but does not support partial transparency: that
is, a pixel can be either completely transparent or
completely opaque. This is not problematic for most games, but if you
want ghosts in you game (or other things that are
partially transparent), GIF is unsuitable. Another problem with GIF, is
that it is was patented, but it seems that the patent
already expired - I am not sure about that, though.
PNG
PNG is like GIF, only better. It can show more colors, has partial
transparency, and is not patented. Some older graphic programs
do not yet support PNG, however.
BMP
The BMP format is quite straightforward: it
stores
without any
compression a two-dimensional array of pixels (it does not store color
information in each pixel but instead has a color pallete, with each
pixel pointing to it's color in the pallete). Because it uses no
compresion, BMP files are very big, so I do not recommend to use them,
except for one case: when drawing maps of levels in your game.
Microsoft Visual Studio includes in it's resource manager an inbuilt
bitmap editor, and that's very useful to draw bitmaps for the outlay of
your levels.
Compression
Most serious graphics programs let you choose
how
much you want to compress your image. It is a trade off between
image quality and loading times. Choose the highest compression rate
that displays your image reasonably, especially
if you want to post your game in the internet, where loading times and
bandwidth capacity are important.
Conclusion
To have images in your Java program, use JPEG for backgrounds, and PNG
for other images. Play with the compresion options
to choose the right compresion ratio that will keep the image size
small but still have reasonable quality.
Did you find the article useful? Please donate here to support
mysuperiorgames.com
Questions, complaints and requests? Send them to admin@mysuperiorgames.com
|