ebook img

Learn SpriteBuilder for iOS Game Development PDF

440 Pages·2014·11.748 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Learn SpriteBuilder for iOS Game Development

Companion BOOKS FOR PROFESSIONALS BY PROFESSIONALS® eBook Available Learn how to use SpriteBuilder and Cocos2D ES SpriteBuilder is the fun and versatile game development environment that L L TIT is a natural successor to Cocos2D, Cocos3D, and Chipmunk2D. In Learn e to create imaginative and fun 2D games TED SpriteBuilder for iOS Game Development, experienced game developer and ar LA author Steffen Itterheim shows you how to get the most out of SpriteBuilder n E R to create a full-featured 2D action game that you can use as a basis for your S own games. p You’ll learn SpriteBuilder best practices, how to incorporate SpriteBuilder r into your game development workflow, and how to use the various features i t of SpriteBuilder, including game physics, scrolling, menus, and playing audio e assets. You’ll learn everything from the basics to advanced topics like visual B effects, soft-body physics, rendering textured polygons, and porting to u Android. You’ll be using both SpriteBuilder and the latest version of Cocos2D, i version 3. If you have a bit of iOS development experience and you want l d to learn to create imaginative 2D games, Learn SpriteBuilder for iOS Game Development is exactly the book you need. e r In this book, you’ll learn: f • o SpriteBuilder and Cocos2D v3 basics, and even how to port r to Android i • O How to design a parallax scrolling game scene • S All about game physics in SpriteBuilder from simple animations to breakable joints and soft-body physics G • Creating and combining visual effects a • Designing menu screens with scroll views m LLeeaarrnn • Font management and localization for your game • e How to incorporate audio assets in your game D e SpriteBuilder iOS v e for l o p m Game Development e n t It t e r h e Steffen Itterheim im COMPANION eBOOK ISBN 978-1-4842-0263-0 54999 Shelve in Mobile Computing SOURCE CODE ONLINE User level: www.apress.com Beginning–Intermediate 9781484202630 For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to access them. Contents at a Glance About the Author ��������������������������������������������������������������������������������������������������������������xvii About the Technical Reviewers �����������������������������������������������������������������������������������������xix Acknowledgments �������������������������������������������������������������������������������������������������������������xxi Introduction ���������������������������������������������������������������������������������������������������������������������xxiii ■ Part I: Introducing SpriteBuilder and cocos2D-iphone version 3 �����������������1 ■ Chapter 1: Introduction �����������������������������������������������������������������������������������������������������3 ■ Chapter 2: Laying the Groundwork����������������������������������������������������������������������������������17 ■ Chapter 3: Controlling and Scrolling �������������������������������������������������������������������������������47 ■ Chapter 4: Physics & Collisions ��������������������������������������������������������������������������������������79 ■ Chapter 5: Timelines & Triggers ������������������������������������������������������������������������������������107 ■ Chapter 6: Menus & Popovers ���������������������������������������������������������������������������������������141 ■ Part II: Getting Down to Business with SpriteBuilder �������������������������������171 ■ Chapter 7: Main Scene and Game State ������������������������������������������������������������������������173 ■ Chapter 8: Selecting and Unlocking Levels �������������������������������������������������������������������209 ■ Chapter 9: Physics Joints ���������������������������������������������������������������������������������������������237 ■ Chapter 10: Soft-Body Physics��������������������������������������������������������������������������������������273 v vi Contents at a Glance ■ Part III: Now You’re a SpriteBuilder Pro! ��������������������������������������������������307 ■ Chapter 11: Audio and Labels ���������������������������������������������������������������������������������������309 ■ Chapter 12: Visual Effects and Animations �������������������������������������������������������������������343 ■ Chapter 13: Porting to Android �������������������������������������������������������������������������������������363 ■ Chapter 14: Debugging & Best Practices ����������������������������������������������������������������������395 Index ���������������������������������������������������������������������������������������������������������������������������������419 Introduction After I updated my previous book, Learn cocos2d 2 to its 3rd edition (published late 2012), I had absolutely no intention of writing another technical book. Certainly not one about Cocos2D. For one, writing a book is a lot of work and that makes it even more painful to see it go out of date even before it is published. This fate is shared by many technical books. On the other hand, Cocos2D in its 2.x version was fairly stable. It also didn’t seem to have gone anywhere. It was merely being maintained at the time, with new features being developed not in the best interest of the community, but instead in the best interest of the company that had, at the time, internalized the development of the open source project Cocos2D. In fall 2013, Apple released iOS 7. With it came Sprite Kit, a 2D rendering engine very similar to Cocos2D at the time. Interest in Cocos2D waned rapidly. It was at that time that Apportable took to Cocos2D. It hired developers from the community to work on Cocos2D to improve it and, ultimately, to make it better than Sprite Kit in every regard. And so work on the 3.x branch began. At the same time, SpriteBuilder was to become not just one of many but the visual editor for Cocos2D. It was well integrated, without quirky setup steps, and there was no having to wait for it to catch up to support newer Cocos2D versions. Over the course of 2014, SpriteBuilder and Cocos2D became one. And exciting new features were added: a fully integrated Objective-C version of the Chipmunk physics engine, a new renderer API that transparently supports both OpenGL and Metal, and built-in shader effects without having to write any shader code. Cocos2D is now more alive and vibrant like never before. When Apportable came to me with the idea for a book on SpriteBuilder and Cocos2D, it didn’t take long for me to accept the challenge. Too much had changed that I didn’t want to leave undocumented, and I was excited that SpriteBuilder and Cocos2D might become what I always hoped they would become. xxiii xxiv Introduction Knowing what goes out of date most quickly, I was confident that I could avoid most of the pitfalls of technology becoming outdated in order to keep the book valid and applicable for a longer time. The fact that the book revolves mostly around SpriteBuilder will certainly help in that regard, as did writing the book against the very latest development branches. As I write these lines, it’s early November 2014 and SpriteBuilder v1.3, which this book covers, has just been submitted to the Mac App Store for review. My next project will have me updating the SpriteBuilder and Cocos2D online documentation. It is intended to be a reference manual that goes well with this book. I will do my best to point out anything that may have changed significantly since the book was published. You will find this documentation online at http://www.cocos2d-swift.org/docs. The first version will cover SpriteBuilder v1.3 and Cocos2D v3.3. I recommend that you keep this link open in a browser tab while reading through this book. Personally, I’m glad that I can recover from writing now by...writing more documentation. Online documentation is a different format with different requirements and possibilities, and I look forward to updating and improving that side of things, too. I also very much look forward to getting your feedback on the SpriteBuilder (http://forum.spritebuilder.com) and Cocos2D (http://forum.cocos2d-swift.org) forums so that I can integrate that feedback in the online documentation. And who knows, perhaps after another period of never wanting to write another book again I’ll get back to making revisions to this book. I’m starting to think that technical writing is, in fact, dangerously addictive. In any case, I hope you will enjoy reading this book as much as I enjoyed getting high on writing it. I Part Introducing SpriteBuilder and Cocos2D-iphone version 3 1 1 Chapter Introduction Welcome to Learn SpriteBuilder for iOS Game Development. This chapter serves as an introduction. It explains what you will get out of this book, the program versions used by the book, and where to get the resource files, just to name a few items. What’s in This Book? In this book, you will learn SpriteBuilder by example. The book will guide you through the creation of a physics-driven, parallax-scrolling game with the help of SpriteBuilder and Cocos2D (Cocos2d-Swift to be precise). The main influence in the design of the example game have been top-selling apps Badland and Leo’s Fortune. The level-based structure will enable you to add more content to the game, even without writing additional code. As your guide, I will walk you through the individual steps necessary to create the game project. Along the way, I’ll explain the SpriteBuilder features, caveats, workarounds, and helpful tips and tricks as you are most likely to come across or need them. The book’s projects and resources are available for download on http://www.apress.com and http://www.spritebuilder.com. It is recommended to use the provided resources, but of course you are free to use your own images, audio, and font files. The example projects allow you to start or continue with any chapter. Caution The book projects are in folders numbered from 00 to 16. The project numbers do not correlate with chapter numbers. You will find the corresponding projects mentioned in each chapter, usually near the end of a chapter. Whenever there’s an easy way and a more efficient way, I’ll be sure to teach you the efficient way. In most cases, it doesn’t even amount to notably more work in any stage of the process. If I had to pick one such efficiency-boosting feature, it would be prefabs accessible through the Tileless Editor View 3 4 CHAPTER 1: Introduction and the Sub File node. It is very important to create as many reusable CCB files for individual parts of your game as is feasible. It’s the object-oriented approach to designing scenes. This book is not a complete reference to SpriteBuilder, although it covers almost all that is nontrivial. You are welcome and encouraged to explore the SpriteBuilder menus, dialogs, preferences, and even its codebase on your own to learn more. However, this is not a requirement to be able to successfully and efficiently use SpriteBuilder. If at any point you need to look something up that’s not explained in this book, you can refer to SpriteBuilder’s online guide maintained by the folks at MakeGamesWith.Us at https://www.makegameswith.us/docs or ask a question in the SpriteBuilder forum at http://www.spritebuilder.com. Who Is This Book for? You’ve already picked up this book and are reading this paragraph to see if it would be a good fit for you. That tells me you have an interest in developing games or graphical apps for iOS, you tend to prefer working visually rather than program everything, or at least you find the concept intriguing. And perhaps you’re already familiar with Cocos2D and want to learn how SpriteBuilder because a visual design tool could change your workflow. If so, this is the right book for you. You certainly want to know whether this book fits your experience level, your programming and technology knowledge, and perhaps even your exact requirements for the app you have in mind. This will be more difficult to assess because I don’t know you, nor your goals. I do know that if you have an interest in SpriteBuilder, Cocos2D, and game development in general you’ll definitely get something out of this book. I’ll try by making some assumptions. These are the three archetype developers I have in mind for whom this book would be a good fit. Beginning developers and those without prior SpriteBuilder experience will get the most of the step-by-step development of a game with SpriteBuilder while learning the SpriteBuilder user interface and basics of Cocos2D. Experienced developers will pleasantly acknowledge the benefits of using a graphical design tool like SpriteBuilder. The workflow tips that I’ll showcase in this book will improve your efficiency. Plus you’ll get some candy on top—tricks and topics you’ll hardly find covered online, such as creating soft-body physics, cool visual effects, and porting your SpriteBuilder game to Android. The Absolute Beginner First, assuming you’ve never ever programmed a mobile app before, if you have no experience with Xcode and Cocoa touch whatsoever, and you don’t know any Objective-C either, I would strongly recommend picking up an introductory book that goes along with this book. Any recent book or tutorial that teaches iOS app development with Objective-C and Xcode from the ground up will be helpful. This book assumes you have a working knowledge of Objective-C and Xcode, so a guide or reference on Objective-C and Xcode would come in handy. Fortunately, there are plenty of tutorials and books to choose from. But start by consulting the Apple Developer Library first. CHAPTER 1: Introduction 5 As a beginner, you can do a lot within SpriteBuilder and reduce the amount of code quite significantly. You may even be able to create simple games with very little programming. However, I’m cautious about spelling this out because it may create false expectations. You may need to tone down your initial expectations for your first SpriteBuilder game, especially considering that at this point it may be almost impossible for you to judge what is and is not possible with SpriteBuilder in the first place. But if you go ahead with a motivation to learn, and perhaps do not try to implement your grandest design as your first game, I’m sure you’ll get along just fine. Expect to invest a lot of time into any and all technology, since this isn’t just a single program you set out to learn—it’s a whole, seemingly overwhelming conglomerate of terms and technologies when you venture into game app development. As long as you stay patient and eager to learn, it won’t be unpleasant. Plus there’s a friendly and helpful community that embraces newcomers like you. The Experienced App Developer My second assumption is that you may be a seasoned iOS app developer but haven’t tried making games yet, perhaps because you would not want to miss out on graphical design tools like Interface Builder. For you, it should be fairly simple to pick up how the Cocos2D framework works, after all there’s plenty of documentation available. You may want to learn specifically how games are designed and how this is different from using Interface Builder. You’ll be able to pick up a lot of these concepts by reading the book. You may need to change some habits and expectations, but besides that I do not see any reason why you wouldn’t benefit from reading this book if your goal is to make games with SpriteBuilder. I suppose the same could be said if you have prior mobile game development experience, just not with Cocos2D or SpriteBuilder. The Experienced Cocos2D Game Developer Finally, I can imagine you may be an experienced Cocos2D developer. Perhaps you haven’t been using the latest Cocos2D version, or perhaps you just want to learn whether you should really give up some coding and do some designs in SpriteBuilder instead, and how that might work out. You’ll find the programming aspects a walk in the park, and you’ll enjoy the workflow benefits of using SpriteBuilder that I’ll present to you throughout the book. You may even be astonished about how much fun it is not to write program code, and you’ll appreciate being able to free your mind from tedious, repetitive programming tasks while being able to do more of the cool programming tricks you haven’t had time to explore yet. Requirements In order to learn from this book, you obviously need to download SpriteBuilder for free from the Mac App Store. To run SpriteBuilder, you need a Mac running OS X 10.8 Mountain Lion or newer. Cocos2D comes bundled with SpriteBuilder—you do not have to download it separately. There’s still a benefit in doing so, however. If you get the installer version from http://www.cocos2d-swift.org/ download and install it, you will have the Cocos2D API reference documentation available in Xcode. But you can also access it online: http://www.cocos2d-swift.org/docs/api.

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.