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

Preface

The introduction of the Apple App 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 App Store, allowing you to make and sell games quickly and easily.

Welcome to Learning Objective-C by Developing iPhone Games. This book will offer you a step-by-step process to develop iPhone games using the Objective-C programming language. You will be intrigued by the use of old games, such as Galaga and Space Invaders, as teaching tools to receive a hands-on understanding of game development. We will teach you everything you need to know in order to use Apple's Xcode integrated development environment. When you are finished, you will be able to program your own games from the ground up using graphics, animations, sounds, and interactivity.

What this book covers

Chapter 1, The Environment – Installing and Working with Xcode, covers how to download, set up, and install Xcode. You will also learn what Xcode is and how we will be using it. This will introduce you to the development environment and the space they will be working on.

Chapter 2, Programming and Objective-C, is a soft introduction to programming languages in general, or a programming language primer if you prefer. When we are done with this chapter, you will have a general understanding of how most programming languages are structured and how this works in games. We will take you through the basics of object-oriented programming and a description of how Objective-C uses classes. We will wrap up the chapter with an explanation of how the model-view-controller design pattern applies to iOS programming.

Chapter 3, iPhone Game Development Basics – The Matching Game, explains the CoreGraphics, Foundation, and UIKit frameworks. We will build a simple user interface using Xcode's interface builder in a single view application. Then, we will use this to create a simple memory game using some basic game logic, UIButtons, and other standard library components.

Chapter 4, Drawing Pictures – Space Invaders, teaches you to program a Space Invaders game using images, views, and the view controller. You will learn how to display a background image for your game and program your alien to drop bombs. You will use these to try and destroy your player using CoreAnimation. You will also create timers in your game using NSTimer methods.

Chapter 5, The Game Engine – Space Invaders Part 2, will expand the Space Invaders game by examining NSObjects and basic object-oriented programming structures to create enemies. You will learn the basics of artificial intelligence, collision detection, and storing information about your invader in objects, properties, and arrays. You will also learn the basics of how to debug your code.

Chapter 6, The Audio Engine – The Simon Memory Game, will create a simple audio-based memory game. In this chapter, you will learn about all of the different audio formats and data formats that can be used for iOS audio. We will explain the AVAudioFoundation frameworks in order for you to add sounds and music to your app. You will learn how to use different types of audio, which can be played back inside your game for both background music and as audio effects.

Chapter 7, User Interactivity – Mini Golf, teaches different ways of programming touch controllers for your app using touch events. We will show you how to program your graphics to move using buttons, gestures, and multitouch interactivity.

Chapter 8, The Galaxy Game, talks about resource management and some basics on planning for what is being used, what is planned to be used, and how these resources are stored. We will use this and everything you have learned previously in order to create your final game similar to Galaga.

Chapter 9, Releasing Your Game, speaks about what needs to be done once you have completed your game; it's not yet finished. You will still need to get your app into the App Store. Preparing your game for the App Store can be a very confusing process; however, we will try and make it a bit easier for you. In this chapter, we are going to introduce you to iTunes Connect, provisioning profiles, and development profiles. We will show you how to set up your code and prepare it for release in the Apple Store and how to avoid some issues that all developers run into at one point or another.

Chapter 10, Conclusion, gives an overview of what we covered in the book and covers in brief other technologies that Apple has to offer.

What you need for this book

In order to get the most out of this book, there are a few essentials you will need:

  • A Mac computer running OS X 10.8.4 or higher (no, you cannot program an iPhone in Windows; sorry)

  • Basic knowledge of programming is helpful

  • Xcode 5.1 (we will explain how and where to get this in the first chapter)

  • Safari or another web browser

  • Internet access

  • If you would like to distribute your apps in the App Store, you are required to have a paid developer account. We will explain how to sign up for a developer account in the first chapter.

Who this book is for

If you are a beginner or an enthusiast who dreams about creating games, or if you have already worked in this domain but need some additional inspiration and knowledge, this book is for you. No programming experience is expected.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Your debugger will go to the first line in the loadingScreen method."

A block of code is set as follows:

-(void)intersectCheck{
  BOOL isConnecting = CGRectIntersectsRect(self.enemies.enemiesBullet.
        bombRect, self.playerOne.playerRect);
  if(isConnecting == true){
    [NSTimer scheduledTimerWithTimeInterval:2
        target:self
        selector:@selector(endScreen)
        userInfo:nil
        repeats:NO];
    [self changeState:RELOADING];
  }
}

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Navigate to View | Debug Area | Show Debug Area."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.