Game Development Reference
In-Depth Information
if (self.center.x < gameController.gameAreaSize.width-100){
if ([gameController stepNumber] % 25 == 0){
if (self.state == STATE_GLOW){
float pan = 1.0 - (self.center.x / gameController.gameAreaSize.width)*2.0;
[gameController playAudio: AUDIO_POWERUP_BLINK volume:.1 pan: pan];
self.state = STATE_NO_GLOW;
} else {
self.state = STATE_GLOW;
}
}
}
}
In Listing 11-12, we see the step: task for the class Powerup . This task is called once per step in
the game and is a place where an actor can specify some of its own behavior. The first test in this
task simply checks if the Powerup is off the left side of the screen and removes itself accordingly.
The second test checks to see if the Powerup should start blinking; if so, every 25 steps it alternates
between STATE_GLOW and STATE_NO_GLOW . If the Powerup has just switched to STATE_NO_GLOW, it plays
the audio AUDIO_POWERUP_BLINK . Notice how the pan for this audio is based on the x value of the
Powerup . This makes it sound like the blinks are coming from one side of the screen or the other.
To observe this effect, play the example code with headphones on.
Summary
In this chapter, we reviewed how to set up a game to be a good iOS citizen by responding
correctly to the user's behaviors and expectations. We also looked at some framework code in
GameController to make playing audio easier for our particular games. We looked at differentiating
background music from sound effects. Lastly, we looked at how we use this framework by exploring
a simple example that played two different sound effects driven by different events in the game.
 
Search WWH ::




Custom Search