LEARN TO MAKE - wizardfu.comwizardfu.com/assets/Learn_to_Make_iPhone_Games-Sample.pdf · Breaking...
Transcript of LEARN TO MAKE - wizardfu.comwizardfu.com/assets/Learn_to_Make_iPhone_Games-Sample.pdf · Breaking...
Lear
n t
o M
ake
iPh
one
Gam
es
LEARN TO MAKEIPHONE GAMES
NAT WEISS
Bullets in a Burning Box
Copyright © 2010-2011 Bullets in a Burning Box, Inc.
All rights reserved.www.iPhoneGameKit.com
The burning box logo is a trademark of Bullets in a Burning Box, Inc.
iPhone, iPad, iPod touch, Xcode, Mac, and Mac OS are trademarks of Apple Inc., registered in the U.S. and other countries. Bullets in a Burning Box Inc. is an independent corporation and
has not been authorized, sponsored, or otherwise approved by Apple Inc.
Cocos2D is a trademark of Ricardo Quesada, registered in the U.S.
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
Bullets in a Burning Box 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.
Printed in the United States of America.
Fourth edition.
For my sister,NAOMI,
who is a fountain of inspiration and caring help.
MAKE THE WORLD A BETTER PLACE --10% of all author royalties are donated to worldwide
not-for-profits, including JustGive.org.
C O N T E N T S
Design Your World 10
Learning to Make Games 10Your Guide 11Be a Go-getter 11Power of Your Subconscious Mind 12Your Game Design 12
Your Toolbox 14
Your Tools 14Your Computer 14Get the SDK 15Get the Map Editor 15Get Art Software 15Get Sound Software 16Running the Project in Xcode 16The Layers of Code & Art 17What’s Next 18
Make Your Own Levels 20
A Tiled Floor 20Adding a Tileset Image 21The Tilesets Palette 22The Obstacles Layer 23The Objects Layer 24Saving Levels In The Right Place 27Building the Game 27Other Layer Properties 31More Objects Types 32Fixing Common Issues 34Build Errors 34Runtime Issues 36The Debug Area and Console 36Remember Base64 Gzip 37
Learn A Little Objective C 40
A Quick Intro 40Object Oriented 40Method (.m) and Header (.h) Files 41
Comment Lines Are Ignored 42Object & Class 42Object Inheritance 43Hierarchy 43Method Signature 45Variables 46Messages 46Go Get Full 47
Cocos2D Basics 48
How to Drag a Sprite 48The Sprite Dragger Project 48Setting Up Cocos2D 50Cocos2D Nodes 50Cocos2D Scenes 51SpriteDragger Layer & Scene 51Anchor Points 53Cocos2D Touch Events 54Touching the Sprite 55Cocos2D Actions 55More Cocos2D Basics 56
Breaking Into the App Code 58
In the Beginning There Was Main 58@class 59Memory Management 59C Functions 59NSObject 60Jump to Definition 61The NS Prefix 61Protocols 61Member Variables 62startApp 62File Counterparts 63Class vs Instance Methods 65CCDirector 67Pointers 67Casting 68Cocos2D Transitions 69
Make Your Own Characters 70
Art By Reiner “Tiles” Prokein 70Sprite Sheet Makers 71Choosing The Sprites 71Fixing the Size and Background 72Exporting the Spritesheet 73Compressed PVR 74Spritesheet Optimization 74HD Spritesheets 74Publish 75Cleaning Up Sprites 75Editing a Spritesheet’s Plist 76Character Profiles 77Printf Formatting 78Bringing Our Character To Life 79Common Solutions 81
The Logic to Load a Level 82
The Game Scene 82Which init? 83The Self Variable 84Indentation Style 85Z Ordering & Tags 85Creating the Level 86Private Methods 87Categories aka Class Extensions 87Xcode’s Auto-complete 88Properties 88Getters and Setters 89The nonatomic Keyword 90CCTMXTiledMap 90CC_CONTENT_SCALE_FACTOR() 92The For..In Loop 92Layer Initialization 93Scheduling an Update 93Selectors 94Creating Level Objects 94NSDictionary 95
The Basics of Touch Input 100
Creating the Player Object 100Touching The Joystick 101
Are You Touching the Joystick? 103Moving the Joystick Button 104Swinging the Sword 107Here Kitty, Kitty 108Character Movement 110Eating Food 112Saving the Game 114
Artificial Intelligence Agency 116
Moody Monsters 116Seeking the Player 118Going Nuts 119Give a King a Bone 120
Let There Be Sound 122
The Making of a Singleton 122Multi Threading 123Synchronized 123Asynchronous Initialization 124Background Loading 126Playing a Sound Effect 129The Main Menu 129Making Your Own Art 131Character Sound Effects 133Making Your Own Sound Effects 136
Monster Checkers 138
Source Code to Another Game 138A Different Genre 138Overview of the Game Objects 139A Game in One Week... Scary? 140Day One: 4 hours 140Day Two: 2 Hours 141Day Three: 6 Hours 142Day Four: 3 Hours 142Day Five: 5 Hours 143Day Six: 3 Hours 143The Game Logic For Checkers 143
Lofty Resolutions 146
The High Resolution Challenge 146
Multiple Projects? 147A Single, Universal Project 148The Scale Method 149The chooseResource Method 150Creating High Resolution Menus 150The Principle: Always Go Hi-Res 152HD TMX Maps 152HD Sprites 152Multitasking 153Base SDK & Deployment Target 154Setting the Game’s Icon 155Concluding Thoughts on Hi-res 156
Beyond Infinity 158
Your Own Game 158Best Practices 159Kobold2D 159Goals, Mini-Goals & the Zipper 159Holes to Explore 160Feedback 161About the Author 161