1. Trang chủ
  2. » Công Nghệ Thông Tin

creating games with cocos2d for iphone 2

388 918 0

Đ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

Thông tin cơ bản

Định dạng
Số trang 388
Dung lượng 25,65 MB

Nội dung

www.it-ebooks.info Creating Games with cocos2d for iPhone 2 Master cocos2d through building nine complete games for the iPhone Paul Nygard BIRMINGHAM - MUMBAI www.it-ebooks.info Creating Games with cocos2d for iPhone 2 Copyright © 2012 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: December 2012 Production Reference: 1171212 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-84951-900-7 www.packtpub.com Cover Image by Abhishek Pandey (abhishek.pandey1210@gmail.com) www.it-ebooks.info Credits Author Paul Nygard Reviewers Dave Hersey Marcio Valenzuela P Acquisition Editor Usha Iyer Lead Technical Editor Llewellyn F. Rozario Technical Editors Sharvari Baet Komal Chheda Kirti Pujari Brandt D'Mello Project Coordinator Abhishek Kori Proofreaders Bob Phillips Bernadette Watkins Indexer Monica Ajmera Mehta Production Coordinator Shantanu Zagade Cover Work Shantanu Zagade www.it-ebooks.info About the Author Paul Nygard has been a computer and technology enthusiast since he was introduced to his rst computer at the age of six. He has spent most of his professional life building reporting and analytical systems for a large company. After teaching himself Objective-C in 2010, he has focused most of his attention on iOS programming. Paul created a personal development label, Troll Cave Games (http://www.trollcavegames.com), to release his mobile gaming efforts. Paul also works as a consultant and developer-for-hire for visionaries in need of a coder. In his leisure time, Paul is passionate about games, books, and music. I would like to thank my family for their support and for allowing me to hide in my troll cave and pursue my passions. This book is for you! I would also like to thank Ricardo Quesada and Steve Oldmeadow, for all their hard work on cocos2d and cocosDenshion. They have helped to mold a new generation of developers by giving us all a wonderful world to play in. And to the cocos2d community: I have never seen such a large group of developers so eager to help each other along. Thanks for the support, advice, and humor over the years. www.it-ebooks.info About the Reviewers Dave Hersey has over 35 years of experience in Apple software development, dating back to the Apple II personal computer in 1977. After a successful career of more than 6 years at Apple Computer, Inc., Dave started Paracoders, Inc. in 2000 focusing on custom Mac OS X-based application and driver development. In 2008, Dave's business expanded into iOS (iPhone) mobile applications, followed by Android applications soon after. Some bigger-named clients include Paramount Home Entertainment, Lionsgate Entertainment, Seagate, Creative Labs, and Kraft. Most recently, Dave's business expansion has included additional mobile and server-side platforms as well as support services. This has led to rebranding his company as "Torchlight Apps" (http://www.torchlightapps.com). Dave is also a moderator and active participant on the cocos2d-iphone.org forums under the username clarus when he's not busy with his wife raising three children, three dogs, three parakeets, four ducks, and seven ducklings at last count. www.it-ebooks.info Marcio Valenzuela P is a biochemist who has studied programming as a hobby for over 12 years. He is perseverant, auto-didactic, and is always looking into the latest technologies. Marcio started by picking up ASP back in the early 1990s as Chief Web Developer for a consulting company that developed web applications for private companies. He also delved into PHP applications with a MySQL database backend. Then in 2008 he started his path down iOS and has had experience developing applications and games for the platform. His experience is mostly in business applications where there exists a cloud-based web service to interact with and more recently in games created in cocos2d. Marcio is cofounder of Activasolutions.com and currently runs a small iOS project called Santiapps.com, which programs for companies wishing to enter the iOS platform. Marcio is a forum moderator at RayWenderlich.com. I would like to acknowledge the time I have taken from raising my son to dedicate to this book. I just hope someday Santiago follows in the programming tradition as it fosters critical skills such as problem solving and innovation which is something we share. www.it-ebooks.info www.PacktPub.com Support les, eBooks, discount offers, and more You might want to visit www.PacktPub.com for support les and downloads related to your book. Did you know that Packt offers eBook versions of every book published, with PDF and ePub les available? You can upgrade to the eBook version at www.PacktPub. com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub.com for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks. TM http://PacktLib.PacktPub.com Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read, and search across Packt's entire library of books. Why Subscribe? • Fully searchable across every book published by Packt • Copy and paste, print and bookmark content • On demand and accessible via web browser Free Access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access. www.it-ebooks.info www.it-ebooks.info Table of Contents Preface 1 Chapter 1: Thanks for the Memory Game 7 The project is 8 Let's build a menu 9 Where is the scene? 10 Building the playeld 12 We need sprites 13 Building a sprite sheet 14 On to the playeld 15 Creating the playeld header 15 Creating the playeld layer 16 The ow of the game 19 A stack of tiles 20 The memory tile class 20 Loading tiles 25 Drawing tiles 26 Adding interactivity 28 Checking for matches 30 Scoring and excitement 31 Animating the score 34 Adding lives and game over 35 Bringing it all together 37 It's quiet too quiet 38 Summary 39 www.it-ebooks.info [...]... Summary 20 2 20 4 20 7 21 0 21 1 21 2 21 4 21 5 Chapter 7: Playing Pool, Old School 21 7 Chapter 8: Shoot, Scroll, Shoot Again 26 9 The game is… 21 7 Overall design 21 8 Building the table 21 8 The Box2D world 22 0 Building the rails 22 0 Building pockets 22 4 Creating the cue stick 22 6 Loading the rules 22 6 Rules.plist 22 9 Rack 'em up 23 2 Building the rack 23 3 Player HUD 23 5 Displaying messages 23 8 Collision handling 24 0... 322 324 327 330 3 32 334 337 339 346 348 349 351 Preface Cocos2d for iPhone is a robust framework for developing 2D games for any iOS device It is powerful, flexible, and best of all it is free to use for your own projects Thousands of apps, including many top selling games, have been written using cocos2d Creating Games with cocos2d for iPhone 2 will take you on a tour of nine very different games, guiding... 24 0 Building the control base 24 4 One-touch control 24 7 Two-touch control 25 0 The rules engine 25 4 Putting balls back 25 9 Checking the table 26 1 The playfield init method 26 5 Summary 26 7 The game is… Design review Tiled – a primer Drawing the ground Logic layers Spawn layer Understanding TMX format Creating an HD map [v] www.it-ebooks.info 26 9 27 0 27 0 27 2 27 3 27 4 27 5 27 5 Table of Contents Implementing... Controlling the hero with SneakyJoystick Tilt controls Interpreting the controls Building the HUD Scene construction Tile helper methods Tile self-identification Smarter hero walking Time for bullets TDBullet class Building the enemy Adding the enemies Collision handling Everybody gets hit Game over, man Smarter enemies Code not covered here Summary 27 6 27 8 28 1 28 2 28 5 28 7 28 9 29 1 29 2 29 3 29 5 29 7 29 8 300 304... snake? Summary The project is… Box2D – a primer Box2D – what is it? Basic parts of Box2D 103 104 105 107 108 109 110 111 113 114 114 115 116 118 120 122 123 124 124 125 126 127 128 128 129 On to the game! 130 World building 130 On the edge 131 Having a ball 133 Setting everything in motion 135 Collision handling 137 Losing your ball 139 Destruction 141 Paddling around 1 42 Paddle fixture 143 Touching the... the project from the default cocos2d v2.x - cocos2d iOS template Once the project is created, we first remove the HelloWorldLayer.h/.m files HelloWorld is a good starting point for learning the code structure, but we don't really want (or need) this boilerplate class for anything (don't forget to remove the #import "HelloWorldLayer.h" at the top of the IntroLayer.m class) For now we'll leave the reference... of Light will only work on a real iOS device [2] www.it-ebooks.info Preface Who this book is for This book is written for people who have basic experience with cocos2d, but want some guidance on how to approach real-world design issues Although the book does revisit some basic concepts, we hit the ground running, so having a basic understanding of cocos2d is recommended At least some knowledge of Objective-C... Deleting moles Touching moles Tying it together Scoring the mole Summary [ ii ] www.it-ebooks.info 41 42 42 44 46 48 51 54 58 60 61 63 65 70 76 77 78 79 80 80 81 82 83 86 87 90 91 91 92 95 96 97 99 100 1 02 Table of Contents Chapter 4: Give a Snake a Snack… 103 Chapter 5: Brick Breaking Balls with Box2D 127 The project is… Design approach Building a better snake Anatomy of a snake segment Dissecting the... statements will be of the basic format: @synthesize propertyName = _variableName; We're planning ahead with this class, including the headers for three methods that we will use for the tile animation: flipTile, showFace, and showBack This class will be responsible for handling its own animation All animation in our game will be done using cocos2d actions Actions are essentially transformations of some sort... 3 12 313 Chapter 9: Running and Running and Running 315 Index 353 The Game Is Design review Building the ground ERTile class Adding gap tiles Scrolling the tiles Parallax background Our hero Animation loading Updating the hero Touch controls Shooting bullets Enemies everywhere Collision handling Getting shot with particles Death of hero Summary [ vi ] www.it-ebooks.info 315 316 317 320 321 322 324 . www.it-ebooks.info Creating Games with cocos2d for iPhone 2 Master cocos2d through building nine complete games for the iPhone Paul Nygard BIRMINGHAM - MUMBAI www.it-ebooks.info Creating Games with cocos2d for. game is… 21 7 Overall design 21 8 Building the table 21 8 The Box2D world 22 0 Building the rails 22 0 Building pockets 22 4 Creating the cue stick 22 6 Loading the rules 22 6 Rules.plist 22 9 Rack 'em. all it is free to use for your own projects. Thousands of apps, including many top selling games, have been written using cocos2d. Creating Games with cocos2d for iPhone 2 will take you on a

Ngày đăng: 05/05/2014, 11:17