Online Book Reader

Home Category

iPhone Game Development - Chris Craft [53]

By Root 1568 0
own application, particularly during development.

//Setup sound engine. Run it at 44Khz to match the sound files

SoundEngine_Initialize(44100);

// Assume the listener is in the center at the start. The sound

// will pan as the position of the rocket changes.

SoundEngine_SetListenerPosition(0.0, 0.0, kListenerDistance);

// Load each of the four sounds used in the game.

SoundEngine_LoadEffect([[bundle pathForResource:@”background” ofType:@”caf”] UTF8String], &_sounds[kSound_Drumbeat]);

//Play start sound

SoundEngine_StartEffect( _sounds[0]);

}

Now you add the keystone piece. The touchesBegan method triggers the drumbeat sound any time the Main View is touched:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

SoundEngine_StartEffect( _sounds[kSound_Drumbeat]);

}

Be sure to set Xcode to Simulator | Distribution and then click the Build and Go button. The application should now load in the Simulator and run. You should see the iDrum application, as shown in Figure 4.14.

FIGURE 4.14

The final iDrum application running in the Simulator


The application is mostly done now and just needs some finishing touches. You should create a nice About Us screen for it, and you will need to come up with a great iPhone application icon for users to see both on the App Store and on the iPhone. You might want to consider using the image of the drum itself and then simply resizing it as needed to make your icon.

There are quite a few virtual drum applications on the App Store. What can you do to this application to make it stand out? Well you could add a setting to let people decide what kind of drum they want to play. You could have a standard drum, a Jamaican drum, or a Congo drum for starters.

Tip

The iPhone is a very feature-rich device, and you should always try to use its capabilities to surprise and delight your application's users. If you make your applications high quality and offer great user experiences, people will come back for more. Any time you raise the bar for what people can expect, you have gone from having a customer to having a fan—and you can never have too many of those.

What if when the user tapped the drum the physical iPhone device itself vibrated? In order for an iPhone SDK application to be able to make the device vibrate, the application must include a reference to the AudioToolbox framework. This is not a problem for the iDrum application because it already includes this reference. But you will want to remember this for the next application you write that will support vibration. It will be a real pain if you overlook this detail.

It only takes one line of code to make the iPhone vibrate:

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

Locate the touchesBegan method in your MainView.m file. It should match the following code:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

SoundEngine_StartEffect( _sounds[kSound_Drumbeat]);

}

You will need to update this method so that it calls the vibration code listed earlier, as follows:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

SoundEngine_StartEffect( _sounds[kSound_Drumbeat]);

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

}

And there you go—you now have a virtual drum with a force feedback feature, all implemented in one line of code in less than a few minutes' time.

Wouldn't it be great if the drum had a quick animation that played whenever the user tapped it? This would make it much more realistic. What if you create a screen where the user could pick a song and the drum would automatically play it, kind of like how the old player pianos could do? You probably have some ideas of your own as well. What are you waiting for—seize the day!

Programming: Bonfire

The last novelty you are going to create in this chapter is Bonfire. Bonfire is meant to be a virtual campfire that users can carry with them anywhere. And at least with this campfire, nobody has to worry about burning down the forest. When you are finished

Return Main Page Previous Page Next Page

®Online Book Reader