iPhone Game Development - Chris Craft [125]
#import “FlipsideViewController.h”
#import @interface MainViewController : UIViewController IBOutlet UILabel *infoLabel; } - (IBAction)showInfo; @end Now, in the implementation of your class, you need to create an instance of a CLLocationManager. After creating the class you need to set the delegate to self and send the message startUpdatingHeading. This tells the location manager to activate and start sending heading information to the assigned delegate: - (void)viewDidLoad { [super viewDidLoad]; CLLocationManager *locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; [locationManager startUpdatingHeading]; } Heading information comes in regular intervals in the form of the message locationManager:didUpdateHeading:. In this message you pass a CLHeading object, which contains properties that report on all the heading data available: - (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading { NSString *heading = [NSString stringWithFormat: @”x:%f\ny:%f\nz:%f\ntrueHeading:%f\n magneticHeading:%f\nheadingAccuracy:%f”, newHeading.x, newHeading.y, newHeading.z, newHeading.trueHeading, newHeading.magneticHeading, newHeading.headingAccuracy]; infoLabel.text = heading; } This simple example is just a new application created from the utility template with the code listed here added. A label was also used to display the raw compass information that is updated every time the message above is fired (Figure 9.8). FIGURE 9.8 A display of the raw compass heading data supplied by CLLocationManager - (BOOL)locationManagerShouldDisplayHeadingCalibration:(CLLocationManager *)manager { return YES; } FIGURE 9.9 If you do not wish to provide a custom calibration message, you can fall back on the default calibration display as rendered by the device. FIGURE 9.10 If you do not wish to use the default display, you can use your own, as shown here in the native compass application. What is a game without sound? Of course, you can still have a game that does not play any sounds and you may even get away with it in some puzzle games. But even the most benign puzzle game can gain new life if you add a little sound to it. When scheduling your game project, don't underestimate the time it will take you to incorporate sound. There's more to it than compiling your sound files into the application bundle. First you have to get your files in the correct format. We have had the best experience using MPEG-4 files for music and CAFF files for sound effects. You can convert your music files to MPEG-4 with a licensed version of QuickTime Pro. This is by far the easiest way to do the conversion. When saving the file we recommend sticking with mono because it is lighter on the CPU and it generates smaller files. The only added value to using anything other than mono is when a player uses headphones to experience stereo-quality sound. However, most of the time players will just use the speaker on the device, so any gain is lost. You will want to use CAFF files for all of your whizzes, bangs, and booms. For this one, Apple has provided us with the tool afconvert.
When tracking compass data, you'll also want to implement the method locationManagerShouldDisplayHeadingCalibration:. If you are not planning to supply calibration instructions that are termed to match your application, you can return YES in this message to have the device display the default message (Figure 9.9):
If you return NO, you will need to supply your own message as the native compass application does in Figure 9.10.
Turning Up the Audio