Learn cocos2d 2: Game Development for iOS
Steffen Itterheim
Language: English
Pages: 531
ISBN: B00ACC69GK
Format: PDF / Kindle (mobi) / ePub
Create compelling 2D games with Learn cocos2d 2: Game Development with iOS. This book shows you how to use the powerful new cocos2d, version 2 game engine to develop games for iPhone and iPad with tilemaps, virtual joypads, Game Center, and more. It teaches you:
- The process and best practices of mobile game development, including sprite batching, texture atlases, parallax scrolling, touch and accelerometer input.
- How to enhance your games using the Box2D and Chipmunk physics engines and other cocos2d-related tools and libraries.
- How to add UIKit views to cocos2d and how to add cocos2d to UIKit apps.
- The ins and outs of the Kobold2D development environment for cocos2d and its pre-configured libraries, including cocos3d and Lua.
Best of all, this book will have you making games right from the very start. It guides you step-by-step through the creation of sample games. These fun examples are modeled after popular App Store games and teach you key concepts of the new cocos2d 2 game engine and relevant tools like TexturePacker (texture atlas), PhysicsEditor (physics collision shapes), Particle Designer (particle effects), Glyph Designer (bitmap fonts), and others.
This book offers a rock-solid introduction to creating games made entirely with cocos2d and little or no iOS SDK and OpenGL code. It also details alternative implementations, identifies the best free and commercial tools for cocos2d game development, features coverage of the author’s improved cocos2d game engine (Kobold2D), and even helps you enhance your game’s marketability on the App Store.
What you’ll learn
- The process and best practices of mobile game development, including sprite batching, texture atlases, parallax scrolling, touch and accelerometer input.
- How to enhance your games using the Box2D and Chipmunk physics engines and other cocos2d-related tools and libraries.
- How to add UIKit views to cocos2d and how to add cocos2d to UIKit apps.
- The ins and outs of the Kobold2D development environment for cocos2d and its pre-configured libraries, including cocos3d and Lua.
Who this book is for
The book is aimed at beginning game developers looking for an easier and even more powerful way to create compelling 2D graphics using OpenGL and Objective-C. It is assumed that the reader will have some knowledge of object-oriented programming and the Apple and iPhone/iPad developer environment.
game’s needs, may be easier to work with. More importantly, the targeted touch handler lets you remove certain touches from the event queue, specifying that you’ve handled this touch and don’t want it to be forwarded to other layers. This makes it easy to sort out if touches are in a specific area of the screen; if they are, you mark the touch as claimed, and all the remaining layers don’t need to do this area check again. To enable the targeted touch handler, add the following method to your
see the block returns void (no return value) and passes an id sender object to the function: block:(void(^)(id sender))block Therefore, the block you need to implement needs to have the following signature: ^(id sender) { // your code here . . . } By now you’ll have noticed the oddly placed caret (^) symbol. That tells the compiler that the following code is a block. Following the caret, you first declare the parameter list in brackets, and following that is your code in curly brackets. So
parentNode as a parameter to the initWithParentNode method. By doing that, the Spider class can add itself to the node hierarchy by calling [parentNode addChild:self], which makes creating an CHAPTER 5: Game Building Blocks 149 instance of a Spider class a one-liner in GameLayer.m because you only need to write [Spider spiderWithParentNode:self]. On the other hand, the spiderSprite should be self-contained because it's created and managed by the Spider class. The spiderSprite is added via
filename, you only need to pass the base name of your animation—in this case ship-anim. The helper method adds the consecutive numbers based on the frameCount parameter and also appends the .png file extension. You can also use the base name for the animation as the name for the animation when you add it to the CCAnimationCache so you don’t have to remember alternate names for the same animation. Previously I named the ship’s animation move. Now it’s called ship-anim, in line with the filenames. You
can’t blend with pixels in the background. If you don’t need any transparency at all, like for background images, you can use the RGB565 format, which provides 5 bits for red, 6 bits for green, and 5 bits for the blue color channel. It doesn’t use an alpha channel. The fact that there are 6 bits for green colors and only 5 bits for the other two color channels has something to do with our hunter-gatherer background. Our retina is simply trained to differentiate better between green color tones,