Book Image

Learning Objective-C by Developing iPhone Games

By : Joseph D. Walters, Amy M. Booker
Book Image

Learning Objective-C by Developing iPhone Games

By: Joseph D. Walters, Amy M. Booker

Overview of this book

<p>The introduction of the Apple Store has empowered thousands, even millions of people to embrace software development. Using Objective-C and the Xcode IDE, you can produce awesome games and launch them on the Apple Store allowing you to make and sell games quickly and easily.</p> <p>From learning the basics of Objective-C to deploying to the App Store, you'll use this book to learn about game development in a matter-of-fact, helpful manner. Whether you're new to game development, or just want to learn how to leverage Apple's own tools to expand your skill set, you'll quickly move from a beginner to an expert.</p> <p>The book kicks off with the basics of game development, and you will take your first steps with using Xcode, the official Apple programming IDE, before moving on to the most important concepts involved in programming games using Objective-C. This book is a hands-on guide to developing the game of your dreams in no time for the Apple Store.</p>
Table of Contents (17 chapters)
Learning Objective-C by Developing iPhone Games
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
3
iPhone Game Development Basics – The Matching Game
Index

Using other mechanisms


iPhone can detect motion events whenever the user shakes, moves, or tilts their device. iPhone has built-in hardware called an accelerometer and a gyroscope, which detect these types of events and pass the information back to your code.

Shake

Let's start with the shake event. When you want to detect a shake, you will need to designate your object as the first responder. To become the first responder, you will need to add the following code to your object:

-(BOOL)canBecomeFirstResponder
{
    return YES;
}

-(void) viewDidAppear:(BOOL)animated
{
    [self becomeFirstResponder];
}

Once you have your responder set up, you need to add a method to handle the event. There are three motion methods that you can use: motionEnded:withEvent:, motionEnded:withEvent:, and motionEnded:withEvent:. These are similar to the touch events we talked about earlier. To detect the shake, you will need to check UIEventSubType that is sent in with the method:

-(void)motionEnded:(UIEventSubtype...