Game Development Reference
In-Depth Information
The code isn't quite as simple as before, but it now allows the engine to support
sprites with different textures. You might be thinking about the worst case
situation for this code; every single sprite that's drawn may force a texture
change. The way to avoid this is to sort out the things being drawn and ensure
that the maximum numbers of vertices that are using the same texture are sent
together. There is another way to minimize the number of texture changes. In-
stead of using lots of separate small textures, textures are grouped together and
combined into a bigger texture; this is often referred to as a texture atlas. Sprites
can then reference this big texture but change the U,V coordinates of their ver-
tices so they only use a small part of it (this is how the font rendering works).
Generally, if it's not a problem, then don't try to fix it!
Adding Sound Support
Sound is very easy to ignore, but it can change the feeling of how a game plays.
Sound is also very easy to add using the excellent OpenAL library. Before wor-
rying about the details, think about how a very simple sound library interface
might work using a code sketch.
SoundManager soundManager = new SoundManager();
soundManager.Add("zap", "zap.wav");
Sound zapSound = soundManager.Play("zap")
if (soundManager.IsSoundPlaying("zap"))
{
soundManager.StopPlaying(zapSound);
}
This code indicates that a sound library should manage sounds in a similar way
to the texture manager. When a sound is played, a reference will be returned.
The reference can be used to control the sound; check if it's playing with the
IsSoundPlaying method or stop it playing with the StopPlaying method.
It would also be nice to have looping sounds and a volume control.
Creating Sound Files
To test the new sound code, some sounds will be needed. Broadly speaking,
games have two categories of sound: sound effects like a gun shooting and
background music or ambient sound.
 
 
Search WWH ::




Custom Search