Game Development Reference
In-Depth Information
Listing 3-5. The Sound Interface
package com.badlogic.androidgames.framework;
public interface Sound {
public void play( float volume);
,,,
public void dispose();
}
The Sound interface is simpler. All we need to do is call its play() method, which again takes
a float parameter to specify the volume. We can call the play() method anytime we want (for
example, when Mr. Nom eats an ink stain). Once we no longer need the Sound instance, we have
to dispose of it to free up the memory that the samples use, as well as other system resources
that are potentially associated.
Note While we covered a lot of ground in this chapter, there's a lot more to learn about audio
programming. We simplified some things to keep this section short and sweet. Usually you
wouldn't specify the audio volume linearly, for example. In our context, it's OK to overlook this little
detail. Just be aware that there's more to it!
Graphics
The last module at the core of our game framework is the graphics module. As you might have
guessed, it will be responsible for drawing images (also known as bitmaps ) to our screen. This
may sound easy, but if you want high-performance graphics, you have to know at least the
basics of graphics programming. Let's start with the basics of 2D graphics.
The first question we need to ask goes like this: how on Earth are the images output to my
display? The answer is rather involved, and we do not necessarily need to know all the details.
We'll just quickly review what's happening inside our computer and the display.
Of Rasters, Pixels, and Framebuffers
Today's displays are raster based. A raster is a two-dimensional grid of so-called picture
elements. You might know them as pixels , and we'll refer to them as such in the subsequent
text. The raster grid has a limited width and height, which we usually express as the number of
pixels per row and per column. If you feel brave, you can turn on your computer and try to make
out individual pixels on your display. Note that we're not responsible for any damage that does
to your eyes, though.
A pixel has two attributes: a position within the grid and a color. A pixel's position is given as two-
dimensional coordinates within a discrete coordinate system. Discrete means that a coordinate
is always at an integer position. Coordinates are defined within a Euclidean coordinate system
imposed on the grid. The origin of the coordinate system is the top-left corner of the grid. The
positive x axis points to the right and the y axis points downward. The last item is what confuses
people the most. We'll come back to it in a minute; there's a simple reason why this is the case.
 
Search WWH ::




Custom Search