Online Book Reader

Home Category

iPhone Game Development - Chris Craft [123]

By Root 1501 0
dimension

In this chapter we cover some of the advanced topics you have not been exposed to in the preceding chapters. The discussion in some sections may not always feel directly relevant to game development. However, you will find that almost any technology can be incorporated into your applications if you are creative. Sometimes these creative combinations can offer an exciting experience that is new and attractive to potential buyers.

Each section in this chapter is focused on different and unrelated advanced topics. At times we reference examples from http://appsamuckcom that cover the topic. Some sections use examples from the iPhone Reference Library—Sample Code, at http://developer.apple.com/iphone/library/navigation/SampleCode.html (login required). Finally, in some instances you will find the specific code you need listed in the section.

Exploring the Camera

The camera is a technology that does not generally come to mind when one thinks of gaming. But ten years ago you may have asked how a guitar can be used in gaming. Today's Guitar Hero and Rock Band are really cashing in on guitar games. You could consider using the camera to snap photos of items in a scavenger hunt; there's one idea. We will leave the creative planning up to you and give you a short tour on how you can integrate the camera into your applications.

We are going to look at some code snippets from the example PhotoFrame, an appsamuckcom original from day 27. The code for PhotoFrame can be found at http://appsamuckcom/day27.html.

Cross-Reference

See Appendix B for all of our 31 days of iPhone apps.

This example lets you select a photo and display it inside of a frame, giving your iPhone the appearance of a framed photo. On the options screen, you select a photo by clicking one of the following two buttons (Figure 9.1):

Select Existing Photo From Library

Take New Photo With Camera

FIGURE 9.1

In the PhotoFrame application, you can choose a photo from your Photo Library or take a new photo with the camera.


If you tap Select Existing Photo From Library, the message selectPhotoFromLibraryClicked is fired:

- (IBAction)selectPhotoFromLibraryClicked {

PhotoPickerController *photoPicker =

[[PhotoPickerController alloc] initWithSourceType:

UIImagePickerControllerSourceTypePhotoLibrary];

[self presentModalViewController:photoPicker animated:TRUE];

[photoPicker release];

}

This message creates an instance of the PhotoPickerController, which is what you want to use to access the Photo Library on your device. Notice that UIImagePickerControllerSourceTypePhotoLibrary is passed in as the source type. This is what tells the PhotoPickerController to read from the Photo Library. Inside of the PhotoPickerController an instance of UIImagePickerController is created, which, when configured with a source type of UIImagePickerControllerSourceTypePhotoLibrary, launches the picker starting in the Photo Library. Users are guided through a series of screens that assist them in selecting and editing their photo (Figures 9.2, 9.3, and 9.4).

FIGURE 9.2

When launched with a source type of UIImagePickerControllerSourceTypePhotoLibrary, the user is given the opportunity to select a Photo Album.


FIGURE 9.3

After selecting a Photo Album, the user can select a specific photo from the album.


FIGURE 9.4

Finally, the user can scale and/or resize the selected photo.


If you tap Take New Photo With Camera, the message takePhotoWithCameraClicked is fired:

- (IBAction)takePhotoWithCameraClicked {

PhotoPickerController *photoPicker =

[[PhotoPickerController alloc]

initWithSourceType:UIImagePickerControllerSourceTypeCamera];

[self presentModalViewController:photoPicker animated:TRUE];

[photoPicker release];

}

The only difference here is that the source type has been set to UIImagePickerControllerSourceTypeCamera. This small change tells the PhotoPickerController to launch the camera instead of an old photo that is already saved (Figure 9.5).

FIGURE 9.5

Capturing a new image with the camera without leaving your

Return Main Page Previous Page Next Page

®Online Book Reader