Learn iPhone and iPad cocos2d Game Development pdf

417 6.9K 2
Learn iPhone and iPad cocos2d Game Development pdf

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Use cutting-edge tools to create exciting iPhone and iPad games Learn iPhone and iPad cocos2d Game Development Steffen Itterheim Learn Learn Download from Wow! eBook <www.wowebook.com> i Learn iPhone and iPad cocos2d Game Development ■ ■ ■ Steffen Itterheim 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-13 (pbk): 978-1-4302-3303-9 ISBN-13 (electronic): 978-1-4302-3304-6 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 orders-ny@springer-sbm.com, or visit www.springeronline.com. For information on translations, please e-mail rights@apress.com, 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. iii To Gabi, the one and only space ant. Sometimes alien, often antsy, always loved. 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 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  ■ 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 ■ 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 ■ 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 [...]... I’m learning something new and I like to think it will work great for you too And since you can base your own games on the book’s source code, I’m looking forward to playing your games in the near future! Don’t forget to let me know about them! You can reach me at steffen @learn- cocos2d. com or visit my website dedicated to learning cocos2d at www .learn- cocos2d. com Why Use cocos2d for iPhone? When game. .. easy—there’s still a lot to learn about game development and programming games But you are reading this book, so I believe you’ve already made up your mind to take this journey And you’ve chosen one of the most interesting game engines to work with: cocos2d for iPhone Developers using cocos2d have a huge variety of backgrounds Some, like me, have been professional game developers for years and even decades Others... applications and games written in Adobe Flash from gaining a foothold in the iOS market Porting to Other Platforms You may have noticed that cocos2d ports exist for various platforms, including Windows and Android They share the same name and development philosophy, but are written in different languages by different authors and have no affiliation with cocos2d for iPhone For example, the Android cocos2d. .. may sound And I wish nothing more than for you to learn a great deal about cocos2d and game development from this book xv ■ ACKNOWLEDGMENTS xvi 1 Chapter 1 Introduction Did you ever imagine yourself writing a computer game and being able to make money selling it? With Apple’s iTunes App Store and the accompanying mobile devices iPhone, iPod Touch, and iPad, it’s now easier than ever Of course, that doesn’t... App Store and relevant to players I’ll walk you through the ideas and technical concepts behind these games in this book, and, of course, how cocos2d and Objective-C make these games tick You’ll find that the source code that comes with the book is enriched 1 2 CHAPTER 1: Introduction with a lot of comments, which should help you navigate and understand all the nooks and crannies of the code Learning... various platforms is in name and philosophy only 5 6 CHAPTER 1: Introduction This Book Is for You I’d like to imagine you picked this book because its title caught your interest I suppose you want to make 2D games for the iPhone and iPad, and the game engine of your choice is cocos2d for iPhone Or maybe you don’t care so much about the game engine but you do want to make 2D games for the iOS devices in... management, let’s just say cocos2d makes it as easy for you as possible, and I’ll help you understand the very simple and basic rules you can follow What You Will Learn I will provide you with a fair share of my game development experiences to show how interactive games are made I believe that learning to program is not at all about memorizing API methods, yet a lot of game development books I’ve read... 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 boon@nanaimostudio.com... 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. .. its own kind of bugs, and every platform has its own technical limitations and challenges Overall, porting iOS games written with cocos2d to other platforms that also have a cocos2d game engine entails almost the same effort as rewriting the game for the target platform using some other game engine This means there’s no switch you can flip and it’ll work The similarity of the cocos2d engines across . <www.wowebook.com> i Learn iPhone and iPad cocos2d Game Development ■ ■ ■ Steffen Itterheim ii Learn iPhone and iPad cocos2d Game Development. cutting-edge tools to create exciting iPhone and iPad games Learn iPhone and iPad cocos2d Game Development Steffen Itterheim Learn Learn Download from Wow! eBook

Ngày đăng: 06/03/2014, 07:20

Từ khóa liên quan

Mục lục

  • Prelim

  • Contents at a Glance

  • Contents

  • About the Author

  • About the Technical Reviewer

  • Acknowledgments

  • Preface

  • Introduction

    • Why Use cocos2d for iPhone?

      • It’s Free

      • It’s Open Source

      • It’s Objective, See?

      • It’s 2D

      • It’s Got Physics

      • It’s Less Technical

      • It’s Still Programming

      • It’s Got a Great Community

      • Important cocos2d Tidbits

        • Section 3.3.1

        • Porting to Other Platforms

        • This Book Is for You

        • Prerequisites

          • Programming Experience

          • Objective-C

Tài liệu cùng người dùng

Tài liệu liên quan