15
Learn iPhone and iPad cocos2d Game Development ■ ■ ■ Steffen Itterheim

Learn iPhone and iPad cocos2d Game Development978-1-4302-3304-6/1.pdf · Learn iPhone and iPad cocos2d Game Development ... What iPhone App Developers Will Learn ... Register as iOS

  • Upload
    hathuan

  • View
    214

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Learn iPhone and iPad cocos2d Game Development978-1-4302-3304-6/1.pdf · Learn iPhone and iPad cocos2d Game Development ... What iPhone App Developers Will Learn ... Register as iOS

i

Learn iPhone and iPad cocos2d Game Development

■ ■ ■

Steffen Itterheim

Page 2: Learn iPhone and iPad cocos2d Game Development978-1-4302-3304-6/1.pdf · Learn iPhone and iPad cocos2d Game Development ... What iPhone App Developers Will Learn ... Register as iOS

ii

Learn iPhone and iPad cocos2d Game Development

Copyright © 2010 by Steffen Itterheim

All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher.

ISBN 978-1-4302-3303-9

ISBN 978-1-4302-3304-6 (eBook)

Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1

Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.

The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.

President and Publisher: Paul Manning Lead Editor: Clay Andres Development Editor: Brian MacDonald Technical Reviewer: Boon Chew Editorial Board: Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Jonathan

Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Duncan Parkes, Jeffrey Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh

Coordinating Editor: Kelly Moritz Copy Editors: Sharon Terdeman and Damon Larson Compositor: MacPS, LLC Indexer: John Collin Artist: April Milne Cover Designer: Anna Ishchenko

Distributed to the book trade worldwide by Springer Science+Business Media, LLC., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com.

For information on translations, please e-mail [email protected], or visit www.apress.com.

Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at www.apress.com/info/bulksales.

The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work.

The source code for this book is available to readers at www.apress.com.

Page 3: Learn iPhone and iPad cocos2d Game Development978-1-4302-3304-6/1.pdf · Learn iPhone and iPad cocos2d Game Development ... What iPhone App Developers Will Learn ... Register as iOS

iii

To Gabi, the one and only space ant.

Sometimes alien, often antsy, always loved.

Page 4: Learn iPhone and iPad cocos2d Game Development978-1-4302-3304-6/1.pdf · Learn iPhone and iPad cocos2d Game Development ... What iPhone App Developers Will Learn ... Register as iOS

iv

Contents at a Glance

■Contents .......................................................................................................... v ■About the Author ........................................................................................... xii ■About the Technical Reviewer...................................................................... xiii ■Acknowledgments.........................................................................................xiv ■Preface ...........................................................................................................xv ■Chapter 1: Introduction ................................................................................... 1�

■Chapter 2: Getting Started............................................................................. 13�

■Chapter 3: Essentials..................................................................................... 39�

■Chapter 4: Your First Game ........................................................................... 65�

■Chapter 5: Game Building Blocks .................................................................. 93�

■Chapter 6: Sprites In-Depth......................................................................... 117�

■Chapter 7: Scrolling with Joy ...................................................................... 141�

■Chapter 8: Shoot ’em Up.............................................................................. 167�

■Chapter 9: Particle Effects........................................................................... 189�

■Chapter 10: Working with Tilemaps ............................................................ 211�

■Chapter 11: Isometric Tilemaps .................................................................. 235�

■Chapter 12: Physics Engines ....................................................................... 263�

■Chapter 13: Pinball Game............................................................................ 287�

■Chapter 14: Game Center............................................................................. 315�

■Chapter 15: Out of the Ordinary................................................................... 347

■Index............................................................................................................ 365

Page 5: Learn iPhone and iPad cocos2d Game Development978-1-4302-3304-6/1.pdf · Learn iPhone and iPad cocos2d Game Development ... What iPhone App Developers Will Learn ... Register as iOS

v

Contents

■Contents at a Glance....................................................................................... iv�

■About the Author ........................................................................................... xii�■About the Technical Reviewer...................................................................... xiii�■Acknowledgments.........................................................................................xiv�

■Preface ...........................................................................................................xv�

■Chapter 1: Introduction ................................................................................... 1�

Why Use cocos2d for iPhone? ................................................................................................................................2�

It’s Free..............................................................................................................................................................2�

It’s Open Source.................................................................................................................................................2�

It’s Objective, See? ............................................................................................................................................2�

It’s 2D.................................................................................................................................................................3�

It’s Got Physics ..................................................................................................................................................3�

It’s Less Technical .............................................................................................................................................3�

It’s Still Programming ........................................................................................................................................4�

It’s Got a Great Community ................................................................................................................................4�

Important cocos2d Tidbits ......................................................................................................................................5�

Section 3.3.1......................................................................................................................................................5�

Porting to Other Platforms .................................................................................................................................5�

This Book Is for You ................................................................................................................................................6�

Prerequisites...........................................................................................................................................................6�

Programming Experience ..................................................................................................................................6�

Objective-C ........................................................................................................................................................6�

What You Will Learn................................................................................................................................................7�

What Beginning iOS Game Developers Will Learn .............................................................................................7�

What iPhone App Developers Will Learn............................................................................................................8�

What Cocos2d Developers Will Learn ................................................................................................................8�

Page 6: Learn iPhone and iPad cocos2d Game Development978-1-4302-3304-6/1.pdf · Learn iPhone and iPad cocos2d Game Development ... What iPhone App Developers Will Learn ... Register as iOS

■ CONTENTS

vi

What’s in This Book ................................................................................................................................................9�

Chapter 2 – Getting Started ...............................................................................................................................9�

Chapter 3 – Essentials .......................................................................................................................................9�

Chapter 4 – Your First Game..............................................................................................................................9�

Chapter 5 – Game Building Blocks ....................................................................................................................9�

Chapter 6 – Sprites In-Depth .............................................................................................................................9�

Chapter 7 – Scrolling with Joy...........................................................................................................................9�

Chapter 8 – Shoot ’em Up................................................................................................................................10�

Chapter 9 – Particle Effects .............................................................................................................................10�

Chapter 10 – Working with Tilemaps...............................................................................................................10�

Chapter 11 – Isometric Tilemaps.....................................................................................................................10�

Chapter 12 – Physics Engines .........................................................................................................................10�

Chapter 13 – Pinball Game ..............................................................................................................................10�

Chapter 14 – Game Center...............................................................................................................................10�

Chapter 15 – Conclusion..................................................................................................................................10�

Questions & Feedback ..........................................................................................................................................11�

■Chapter 2: Getting Started............................................................................. 13�

What You Need to Get Started ..............................................................................................................................13�

System Requirements......................................................................................................................................13�

Register as iOS Developer ...............................................................................................................................14�

Certificates & Provisioning Profiles..................................................................................................................14�

Download & Install the iPhone SDK .................................................................................................................14�

Download & Install cocos2d.............................................................................................................................15�

The HelloWorld Application...................................................................................................................................19�

Locating the HelloWorld files ...........................................................................................................................20�

Resources ........................................................................................................................................................21�

Other Sources ..................................................................................................................................................21�

Classes.............................................................................................................................................................22�

Memory Management with cocos2d.....................................................................................................................27�

Changing the World ..............................................................................................................................................29�

What Else You Should Know .................................................................................................................................31�

The iOS Devices ...............................................................................................................................................32�

About Memory Usage.......................................................................................................................................33�

The Simulator...................................................................................................................................................35�

About Logging..................................................................................................................................................36�

Conclusion ............................................................................................................................................................36�

■Chapter 3: Essentials..................................................................................... 39�

Singletons in cocos2d...........................................................................................................................................39�

The Director ..........................................................................................................................................................41�

The Scene Graph...................................................................................................................................................41�

The CCNode Class Hierarchy ................................................................................................................................43�

CCNode .................................................................................................................................................................43�

Working with Nodes.........................................................................................................................................43�

Working with Actions.......................................................................................................................................44�

Scheduled Messages.......................................................................................................................................45�

Scenes and Layers................................................................................................................................................48�

CCScene...........................................................................................................................................................49�

Page 7: Learn iPhone and iPad cocos2d Game Development978-1-4302-3304-6/1.pdf · Learn iPhone and iPad cocos2d Game Development ... What iPhone App Developers Will Learn ... Register as iOS

■ CONTENTS

vii

Scenes and Memory ........................................................................................................................................49�

Pushing and Popping Scenes ..........................................................................................................................50�

CCTransitionScene...........................................................................................................................................51�

CCLayer............................................................................................................................................................52�

CCSprite ................................................................................................................................................................56�

Anchor Points Demystified...............................................................................................................................56�

Texture Dimensions .........................................................................................................................................57�

CCLabel .................................................................................................................................................................57�

Menus ...................................................................................................................................................................58�

Actions ..................................................................................................................................................................60�

Repeating Actions............................................................................................................................................61�

Ease Actions ....................................................................................................................................................61�

Action Sequences ............................................................................................................................................62�

Instant Actions .................................................................................................................................................62�

Cocos2d Test Cases..............................................................................................................................................63�

Conclusion ............................................................................................................................................................63�

■Chapter 4: Your First Game ........................................................................... 65�

Step-By-Step Project Setup..................................................................................................................................66�

Adding the Player Sprite .......................................................................................................................................71�

Accelerometer Input .............................................................................................................................................74�

First Test Run........................................................................................................................................................75�

Player Velocity ......................................................................................................................................................75�

Adding Obstacles ..................................................................................................................................................78�

Collision Detection ................................................................................................................................................84�

Score Label ...........................................................................................................................................................85�

Introducing CCBitmapFontAtlas and Hiero............................................................................................................86�

Adding Audio.........................................................................................................................................................89�

Porting to iPad ......................................................................................................................................................90�

Conclusion ............................................................................................................................................................91�

■Chapter 5: Game Building Blocks .................................................................. 93�

Working with Multiple Scenes ..............................................................................................................................93�

Adding More Scenes........................................................................................................................................93�

Loading Next Paragraph, Please Stand By.......................................................................................................95�

Working with Multiple Layers ...............................................................................................................................98�

How to Best Implement Levels ......................................................................................................................103�

CCColorLayer .................................................................................................................................................104�

Subclassing Game Objects from CCSprite ..........................................................................................................105�

Composing Game Objects using CCSprite ..........................................................................................................106�

Curiously Cool CCNode Classes ..........................................................................................................................112�

CCProgressTimer ...........................................................................................................................................112�

CCParallaxNode .............................................................................................................................................113�

CCRibbon .......................................................................................................................................................114�

CCMotionStreak .............................................................................................................................................115�

Conclusion ..........................................................................................................................................................116�

■Chapter 6: Sprites In-Depth......................................................................... 117�

CCSpriteBatchNode.............................................................................................................................................117�

When to Use the CCSpriteBatchNode ............................................................................................................119�

Page 8: Learn iPhone and iPad cocos2d Game Development978-1-4302-3304-6/1.pdf · Learn iPhone and iPad cocos2d Game Development ... What iPhone App Developers Will Learn ... Register as iOS

■ CONTENTS

viii

Demo Projects................................................................................................................................................119�

Sprite Animations the Hard Way .........................................................................................................................124�

Animation Helper Category .................................................................................................................................126�

Working with Texture Atlases .............................................................................................................................128�

What Is a Texture Atlas? ................................................................................................................................128�

Introducing Zwoptex ......................................................................................................................................129�

Creating a Texture Atlas with Zwoptex Desktop............................................................................................130�

Using the Texture Atlas with Cocos2d ...........................................................................................................134�

Updating the CCAnimation Helper Category ..................................................................................................136�

All into One and One for All ............................................................................................................................137�

Do It Yourself ......................................................................................................................................................138�

Conclusion ..........................................................................................................................................................139�

■Chapter 7: Scrolling with Joy ...................................................................... 141�

Advanced Parallax Scrolling ...............................................................................................................................141�

Creating the Background As Stripes..............................................................................................................141�

Re-creating the Background in Code.............................................................................................................144�

Moving the ParallaxBackground ....................................................................................................................146�

Parallax Speed Factors ..................................................................................................................................147�

Scrolling to Infinity and Beyond .....................................................................................................................149�

Fixing the Flicker ...........................................................................................................................................151�

Repeat, repeat, repeat ...................................................................................................................................152�

A Virtual Joypad..................................................................................................................................................153�

Introducing SneakyInput ................................................................................................................................154�

Integrating SneakyInput.................................................................................................................................155�

Touch Button to Shoot ...................................................................................................................................156�

Skinning the Button .......................................................................................................................................158�

Controlling the Action ....................................................................................................................................160�

Digital Controls ..............................................................................................................................................164�

An Alternative: GPJoystick .............................................................................................................................164�

Conclusion ..........................................................................................................................................................164�

■Chapter 8: Shoot ’em Up.............................................................................. 167�

Adding the BulletCache Class .............................................................................................................................167�

What about Enemies? .........................................................................................................................................171�

The Entity Class Hierarchy ..................................................................................................................................173�

The EnemyEntity Class...................................................................................................................................174�

The EnemyCache Class..................................................................................................................................177�

The Component Classes ................................................................................................................................181�

Shooting Things ..................................................................................................................................................183�

A Healthbar for the Boss .....................................................................................................................................185�

Conclusion ..........................................................................................................................................................188�

■Chapter 9: Particle Effects........................................................................... 189�

Example Particle Effects .....................................................................................................................................189�

Creating a Particle Effect the Hard Way..............................................................................................................192�

Variance Properties........................................................................................................................................195�

Number of Particles .......................................................................................................................................195�

Emitter Duration.............................................................................................................................................196�

Emitter Modes................................................................................................................................................196�

Page 9: Learn iPhone and iPad cocos2d Game Development978-1-4302-3304-6/1.pdf · Learn iPhone and iPad cocos2d Game Development ... What iPhone App Developers Will Learn ... Register as iOS

■ CONTENTS

ix

Particle Position .............................................................................................................................................199�

Particle Size ...................................................................................................................................................199�

Particle Direction ...........................................................................................................................................199�

Particle Lifetime.............................................................................................................................................200�

Particle Color .................................................................................................................................................200�

Particle Blend Mode.......................................................................................................................................201�

Particle Texture..............................................................................................................................................202�

Introducing the Particle Designer .......................................................................................................................202�

Using Particle Designer Effects......................................................................................................................205�

Sharing Particle Effects .................................................................................................................................207�

Shoot ’em Up with Particle Effects .....................................................................................................................208�

Conclusion ..........................................................................................................................................................210�

■Chapter 10: Working with Tilemaps ............................................................ 211�

What Is a Tilemap? .............................................................................................................................................211�

Preparing Images with Zwoptex .........................................................................................................................214�

Tiled Map Editor..................................................................................................................................................216�

Creating a New Tilemap.................................................................................................................................216�

Designing a Tilemap ......................................................................................................................................218�

Using Orthogonal Tilemaps with Cocos2d ..........................................................................................................221�

Locating Touched Tiles ..................................................................................................................................224�

An Exercise in Optimization and Readability..................................................................................................227�

Working with the Object Layer.......................................................................................................................227�

Drawing the Object Layer Rectangles............................................................................................................229�

Scrolling the Tilemap .....................................................................................................................................232�

Conclusion ..........................................................................................................................................................233�

■Chapter 11: Isometric Tilemaps .................................................................. 235�

Designing Isometric Tile Graphics ......................................................................................................................236�

Isometric Tilemap Editing with Tiled...................................................................................................................240�

Creating a New Isometric Tilemap.................................................................................................................240�

Creating a New Isometric Tileset...................................................................................................................241�

Laying Down Some Ground Rules..................................................................................................................242�

Isometric Game Programming ............................................................................................................................244�

Loading the Isometric Tilemap in Cocos2d....................................................................................................244�

Setup Cocos2d for Isometric Tilemaps ..........................................................................................................244�

Locating an Isometric Tile..............................................................................................................................246�

Scrolling the Isometric Tilemap .....................................................................................................................248�

This World Deserves a Better End..................................................................................................................249�

Adding a Movable Player Character...............................................................................................................253�

Adding More Content to the Game......................................................................................................................260�

Conclusion ..........................................................................................................................................................261�

■Chapter 12: Physics Engines ....................................................................... 263�

Basic Concepts of Physics Engines ....................................................................................................................263�

Limitations of Physics Engines ...........................................................................................................................264�

The Showdown: Box2D vs. Chipmunk ................................................................................................................264�

Box2D..................................................................................................................................................................265�

The World According to Box2D ......................................................................................................................266�

Restricting Movement to the Screen .............................................................................................................268�

Page 10: Learn iPhone and iPad cocos2d Game Development978-1-4302-3304-6/1.pdf · Learn iPhone and iPad cocos2d Game Development ... What iPhone App Developers Will Learn ... Register as iOS

■ CONTENTS

x

Converting Points...........................................................................................................................................270�

Adding Boxes to the Box2D World .................................................................................................................271�

Connecting Sprites with Bodies.....................................................................................................................272�

Collision Detection .........................................................................................................................................273�

Joint Venture..................................................................................................................................................276�

Chipmunk............................................................................................................................................................277�

Objectified Chipmunk.....................................................................................................................................277�

Chipmunks in Space ......................................................................................................................................278�

Boxing-In the Boxes.......................................................................................................................................279�

Adding Ticky-Tacky Little Boxes....................................................................................................................280�

Updating the Boxes’ Sprites...........................................................................................................................282�

A Chipmunk Collision Course .........................................................................................................................283�

Joints for Chipmunks.....................................................................................................................................285�

Conclusion ..........................................................................................................................................................286�

■Chapter 13: Pinball Game............................................................................ 287�

Shapes: Convex and Counterclockwise ..............................................................................................................288�

Working with VertexHelper .................................................................................................................................289�

Creating the Pinball Table...................................................................................................................................291�

Box2D Debug Drawing ...................................................................................................................................296�

Adding Dynamic Elements ..................................................................................................................................297�

The BodyNode Class ......................................................................................................................................298�

The Ball ..........................................................................................................................................................301�

The Bumpers..................................................................................................................................................305�

The Plunger....................................................................................................................................................306�

The Flippers ...................................................................................................................................................310�

Conclusion ..........................................................................................................................................................314�

■Chapter 14: Game Center............................................................................. 315�

Enabling Game Center ........................................................................................................................................315�

Creating Your App in iTunes Connect ............................................................................................................316�

Setting Up Leaderboards and Achievements.................................................................................................317�

Creating a Cocos2d Xcode Project.................................................................................................................317�

Configuring the Xcode Project .......................................................................................................................318�

Summary .......................................................................................................................................................322�

Game Kit Programming.......................................................................................................................................323�

The GameKitHelper Delegate .........................................................................................................................323�

Checking for Game Center Availability...........................................................................................................324�

Authenticating the Local Player .....................................................................................................................325�

Block Objects .................................................................................................................................................328�

Receiving the Local Player’s Friend List ........................................................................................................330�

Leaderboards .................................................................................................................................................332�

Achievements ................................................................................................................................................336�

Matchmaking .................................................................................................................................................341�

Conclusion ..........................................................................................................................................................346�

■Chapter 15: Out of the Ordinary................................................................... 347�

Useful Technologies............................................................................................................................................348�

Social Networks.............................................................................................................................................348�

Socket Server Technology .............................................................................................................................349�

Page 11: Learn iPhone and iPad cocos2d Game Development978-1-4302-3304-6/1.pdf · Learn iPhone and iPad cocos2d Game Development ... What iPhone App Developers Will Learn ... Register as iOS

■ CONTENTS

xi

Ads and Analytics ..........................................................................................................................................350�

Push Notification Providers............................................................................................................................351�

Source Code Projects to Benefit From................................................................................................................351�

Sapus Tongue Source Code ...........................................................................................................................351�

LevelSVG ........................................................................................................................................................352�

The iPhone RPG Game Kit ..............................................................................................................................352�

Line-Drawing Game Starterkit .......................................................................................................................353�

For Your Reference .............................................................................................................................................353�

Working with Publishers .....................................................................................................................................355�

Finding Freelancers ............................................................................................................................................356�

Finding Free Art and Audio .................................................................................................................................357�

Finding the Tools of the Trade ............................................................................................................................357�

Marketing............................................................................................................................................................358�

Marketing Your Game and Your Self..............................................................................................................358�

Public Relations and Press Releases .............................................................................................................360�

Where to Find Help .............................................................................................................................................361�

Cocos2d Home Page ......................................................................................................................................361�

Stack Exchange Network...............................................................................................................................362�

Tutorials and FAQs.........................................................................................................................................362�

Famous Last Words ............................................................................................................................................363�

Conclusion ..........................................................................................................................................................363�

■Index............................................................................................................ 365

Page 12: Learn iPhone and iPad cocos2d Game Development978-1-4302-3304-6/1.pdf · Learn iPhone and iPad cocos2d Game Development ... What iPhone App Developers Will Learn ... Register as iOS

■ ACKNOWLEDGMENTS

xii

About the Author

Steffen Itterheim has been a game development enthusiast since the early 1990s. His work in the Doom and Duke Nukem 3D communities landed him his first freelance job as beta tester for 3D Realms. He has been a professional game developer for well over ten years, having worked most of his career as a game play and tools programmer for Electronic Arts Phenomic. His first contact with cocos2d was in 2009, when he cofounded an aspiring iOS games startup company called Fun Armada. He loves to teach and enable other game developers so that they can work smarter, not harder. Occasionally you’ll find him strolling around in the lush vineyards near his domicile at daytime, and the desert of Nevada at night, collecting bottle caps.

Page 13: Learn iPhone and iPad cocos2d Game Development978-1-4302-3304-6/1.pdf · Learn iPhone and iPad cocos2d Game Development ... What iPhone App Developers Will Learn ... Register as iOS

■ CONTENTS

xiii

About the Technical Reviewer

Boon Chew is the managing director for Nanaimo Studio, a game studio based out of Seattle and Shanghai that specializes in web and mobile games. He has extensive experience with game development and interactive media, having previously worked for companies such as Vivendi Universal, Amazon, Microsoft, and various game studios and advertising agencies. His passion is in building things and working with great people. You can reach Boon at [email protected].

Page 14: Learn iPhone and iPad cocos2d Game Development978-1-4302-3304-6/1.pdf · Learn iPhone and iPad cocos2d Game Development ... What iPhone App Developers Will Learn ... Register as iOS

■ ACKNOWLEDGMENTS

xiv

Acknowledgments

This is the part of the book that make me a little anxious. I don’t want to forget anyone who has been instrumental and helpful in creating this book, yet I know I can’t mention each and every one of you. If you’re not mentioned here, that doesn’t mean I’m not thankful for your contribution! Give me a pen and I’ll scribble your name right here in your copy of the book, and I’ll sincerely apologize for not having mentioned you here in the first place.

My first thanks go to you, dear reader. Without you, this book wouldn’t make any sense. Without knowing that you might read and enjoy this book, and hopefully learn from it, I probably wouldn’t even have considered writing it in the first place. I’ve received valuable insights and requests from my blog readers and other people I’ve met or mailed during the course of this book. Thank you all!

Now follow the people who helped get this book written, in the order I met them.

My first thanks go to Jack Nutting, who put the idea of writing a book on cocos2d in my head in the first place. I’m grateful that he did not sugarcoat how much work goes into writing a book, so I wasn’t unprepared.

Clay Andres I have to thank for being such a kind person, whose input on my chapter proposals were invaluable and to the point. He helped me form the idea of what the book was to become, and he’s generally a delightful person to talk to. Clay, I hope that storm did not flood your house.

Many thanks to Kelly Moritz, the coordinating editor, who though incredibly busy always found the time and patience to answer my questions and follow up on my requests. When chaos ensued, she was the one to put everything back in order and made it happen.

Lots and lots of feedback and suggestions I received from Brian MacDonald, the development editor for the book, and Boon Chew, the technical reviewer. They made me go to even greater lengths. Brian helped me understand many of the intricacies of writing a book while Boon pointed out a lot of technical inaccuracies and additional explanations needed. Many thanks to both of you.

Many thanks go to the copy editors, Sharon Terdeman and Damon Larson. Without you, the book’s text would be rife with syntax errors and compiler warnings, to put it in programmer’s terms. Sharon, when you said that my chapters are always easy work, I actually didn’t believe you even though I know you’re the expert. And Damon, thanks for putting on the reader’s hat and suggesting all those confusing paragraphs to be rephrased.

I also wish to thank Bernie Watkins, who managed the Alpha Book feedback and my contracts. Thanks also to Chris Guillebeau for being an outstanding inspirational blogger and role model.

Of course my friends and family all took some part in writing this book, through both feedback and plain-and-simple patience with putting up with my writing spree. Thank you!

Page 15: Learn iPhone and iPad cocos2d Game Development978-1-4302-3304-6/1.pdf · Learn iPhone and iPad cocos2d Game Development ... What iPhone App Developers Will Learn ... Register as iOS

■ CONTENTS

xv

Preface

In May 2009 I made first contact. For the first time in my life, I was subjected to the Mac OS platform and started learning Xcode, Objective-C, and cocos2d. Even for an experienced developer, it was a struggle. It was at that time that I realized that cocos2d was good, but it lacked documentation, tutorials, and how-to articles—especially when compared with the other technologies I was learning at the time.

Fast forward a year to May 2010. I had completed four cocos2d projects. My Objective-C and cocos2d had become fluent. It pained me to see how other developers were still struggling with the same basic issues and were falling victim to the same misconceptions that I did about a year earlier. The cocos2d documentation was still severely lacking.

I knew that other developers using cocos2d were having great success attracting readers to their blogs by writing tutorials and sharing what they know about cocos2d. To date, most of the cocos2d documentation is actively being created in a decentralized fashion by other developers. I saw a need for a web site to channel all of the information that’s spread over so many different web sites.

I created the www.learn-cocos2d.com web site to share what I knew about cocos2d and game development, to write tutorials and FAQs, and to redirect readers interested in cocos2d to all the important sources of information. In turn, I would be selling cocos2d-related products, hoping it might one day bring me close to the ultimate goal of becoming financially independent. The business model has been proven to work by many shining examples. And I enjoy helping others, having been the go-to guy in all companies I’ve worked for. I knew I could make the web site a win for everyone. I was excited.

From day one, the web site was a success—beyond my wildest imaginations. Then, within 24 hours of taking the web site live, Jack Nutting asked me if I had considered writing a cocos2d book. The rest is history, and the result is the book you’re reading right now.

I took everything I had in mind for the web site and put it in the book. But that alone would have amounted to maybe a quarter of the book, at most. I hope the four months I spent writing the book full-time paid off by being able to provide an unprecedented level of detail on how cocos2d works, and how to work with cocos2d.

I learned a lot in the process, including a lot of things I didn’t even expect not to know, weird as that may sound. And I wish nothing more than for you to learn a great deal about cocos2d and game development from this book.