Learn iPhone and iPad cocos2d Game Development

Book description

Learn iPhone and iPad Cocos2D Game Development provides a rock-solid introduction to the cocos2d iPhone game engine and related tools. It focuses on the process of creating several games made entirely with cocos2d and little to no iPhone SDK and OpenGL code. By creating 2-3 sample games over the course of the book, you'll learn key concepts of the cocos2d game engine and relevant tools like Zwoptex (TextureAtlas), ParticleDesigner (Particle Effects), and others.

The example games are modeled after popular App Store games so that they are relevant, recognizable, and immediately fun and inspiring. The games increase in complexity and highlight common recurring cocos2d beginner questions. As you move along, you'll learn about possible stumbling blocks and how to navigate them successfully. As you move from beginning to advanced, you'll encounter general game programming wisdom, tips for performance improvement, as well as pointers to alternative implementations and further reading.

It is assumed that the reader has previous programming knowledge but not necessarily with Objective-C. Related topics such as Xcode, Objective-C, the iPhone SDK, and OpenGL are only discussed where absolutely necessary.

Please contact helpdesk@apress.com for companion material of this title.

Table of contents

  1. Copyright
  2. About the Author
  3. About the Technical Reviewer
  4. Acknowledgments
  5. Preface
  6. 1. Introduction
    1. 1.1. Why Use cocos2d for iPhone?
      1. 1.1.1. It's Free
      2. 1.1.2. It's Open Source
      3. 1.1.3. It's Objective, See?
      4. 1.1.4. It's 2D
      5. 1.1.5. It's Got Physics
      6. 1.1.6. It's Less Technical
      7. 1.1.7. It's Still Programming
      8. 1.1.8. It's Got a Great Community
    2. 1.2. Important cocos2d Tidbits
      1. 1.2.1. Section 3.3.1
      2. 1.2.2. Porting to Other Platforms
    3. 1.3. This Book Is for You
    4. 1.4. Prerequisites
      1. 1.4.1. Programming Experience
      2. 1.4.2. Objective-C
    5. 1.5. What You Will Learn
      1. 1.5.1. What Beginning iOS Game Developers Will Learn
      2. 1.5.2. What iPhone App Developers Will Learn
      3. 1.5.3. What Cocos2d Developers Will Learn
    6. 1.6. What's in This Book
      1. 1.6.1. Chapter 2 – Getting Started
      2. 1.6.2. Chapter 3 – Essentials
      3. 1.6.3. Chapter 4 – Your First Game
      4. 1.6.4. Chapter 5 – Game Building Blocks
      5. 1.6.5. Chapter 6 – Sprites In-Depth
      6. 1.6.6. Chapter 7 – Scrolling with Joy
      7. 1.6.7. Chapter 8 – Shoot 'em Up
      8. 1.6.8. Chapter 9 – Particle Effects
      9. 1.6.9. Chapter 10 – Working with Tilemaps
      10. 1.6.10. Chapter 11 – Isometric Tilemaps
      11. 1.6.11. Chapter 12 – Physics Engines
      12. 1.6.12. Chapter 13 – Pinball Game
      13. 1.6.13. Chapter 14 – Game Center
      14. 1.6.14. Chapter 15 – Conclusion
    7. 1.7. Questions & Feedback
  7. 2. Getting Started
    1. 2.1. What You Need to Get Started
      1. 2.1.1. System Requirements
      2. 2.1.2. Register as iOS Developer
      3. 2.1.3. Certificates & Provisioning Profiles
      4. 2.1.4. Download & Install the iPhone SDK
      5. 2.1.5. Download & Install cocos2d
        1. 2.1.5.1. Install cocos2d Xcode Project Templates
        2. 2.1.5.2. Create a cocos2d Application
    2. 2.2. The HelloWorld Application
      1. 2.2.1. Locating the HelloWorld files
      2. 2.2.2. Resources
      3. 2.2.3. Other Sources
        1. 2.2.3.1. Main.m
        2. 2.2.3.2. Precompiled Prefix Header
      4. 2.2.4. Classes
        1. 2.2.4.1. HelloWorldAppDelegate
          1. 2.2.4.1.1. Device Orientation
          2. 2.2.4.1.2. Animation Interval
          3. 2.2.4.1.3. Display FPS
        2. 2.2.4.2. HelloWorldScene
    3. 2.3. Memory Management with cocos2d
    4. 2.4. Changing the World
    5. 2.5. What Else You Should Know
      1. 2.5.1. The iOS Devices
      2. 2.5.2. About Memory Usage
      3. 2.5.3. The Simulator
        1. 2.5.3.1. Can't Assess Performance
        2. 2.5.3.2. Can't Assess Memory Usage
        3. 2.5.3.3. Can't Use All iOS Device Features
        4. 2.5.3.4. Runtime Behavior Can Differ
      4. 2.5.4. About Logging
    6. 2.6. Conclusion
  8. 3. Essentials
    1. 3.1. Singletons in cocos2d
    2. 3.2. The Director
    3. 3.3. The Scene Graph
    4. 3.4. The CCNode Class Hierarchy
    5. 3.5. CCNode
      1. 3.5.1. Working with Nodes
      2. 3.5.2. Working with Actions
      3. 3.5.3. Scheduled Messages
    6. 3.6. Scenes and Layers
      1. 3.6.1. CCScene
      2. 3.6.2. Scenes and Memory
      3. 3.6.3. Pushing and Popping Scenes
      4. 3.6.4. CCTransitionScene
      5. 3.6.5. CCLayer
        1. 3.6.5.1. Receiving Touch Events
        2. 3.6.5.2. Receiving Accelerometer Events
    7. 3.7. CCSprite
      1. 3.7.1. Anchor Points Demystified
      2. 3.7.2. Texture Dimensions
    8. 3.8. CCLabel
    9. 3.9. Menus
    10. 3.10. Actions
      1. 3.10.1. Repeating Actions
      2. 3.10.2. Ease Actions
      3. 3.10.3. Action Sequences
      4. 3.10.4. Instant Actions
    11. 3.11. Cocos2d Test Cases
    12. 3.12. Conclusion
  9. 4. Your First Game
    1. 4.1. Step-By-Step Project Setup
    2. 4.2. Adding the Player Sprite
    3. 4.3. Accelerometer Input
    4. 4.4. First Test Run
    5. 4.5. Player Velocity
    6. 4.6. Adding Obstacles
    7. 4.7. Collision Detection
    8. 4.8. Score Label
    9. 4.9. Introducing CCBitmapFontAtlas and Hiero
    10. 4.10. Adding Audio
    11. 4.11. Porting to iPad
    12. 4.12. Conclusion
  10. 5. Game Building Blocks
    1. 5.1. Working with Multiple Scenes
      1. 5.1.1. Adding More Scenes
      2. 5.1.2. Loading Next Paragraph, Please Stand By
    2. 5.2. Working with Multiple Layers
      1. 5.2.1. How to Best Implement Levels
        1. 5.2.1.1. Scenes as Levels
        2. 5.2.1.2. Layers as Levels
      2. 5.2.2. CCColorLayer
    3. 5.3. Subclassing Game Objects from CCSprite
    4. 5.4. Composing Game Objects using CCSprite
    5. 5.5. Curiously Cool CCNode Classes
      1. 5.5.1. CCProgressTimer
      2. 5.5.2. CCParallaxNode
      3. 5.5.3. CCRibbon
      4. 5.5.4. CCMotionStreak
    6. 5.6. Conclusion
  11. 6. Sprites In-Depth
    1. 6.1. CCSpriteBatchNode
      1. 6.1.1. When to Use the CCSpriteBatchNode
      2. 6.1.2. Demo Projects
        1. 6.1.2.1. A Common and Fatal Mistake
        2. 6.1.2.2. Bullets Without a SpriteBatch
        3. 6.1.2.3. Introducing the CCSpriteBatchNode
        4. 6.1.2.4. Optimizations
    2. 6.2. Sprite Animations the Hard Way
    3. 6.3. Animation Helper Category
    4. 6.4. Working with Texture Atlases
      1. 6.4.1. What Is a Texture Atlas?
      2. 6.4.2. Introducing Zwoptex
      3. 6.4.3. Creating a Texture Atlas with Zwoptex Desktop
      4. 6.4.4. Using the Texture Atlas with Cocos2d
      5. 6.4.5. Updating the CCAnimation Helper Category
      6. 6.4.6. All into One and One for All
    5. 6.5. Do It Yourself
    6. 6.6. Conclusion
  12. 7. Scrolling with Joy
    1. 7.1. Advanced Parallax Scrolling
      1. 7.1.1. Creating the Background As Stripes
      2. 7.1.2. Re-creating the Background in Code
      3. 7.1.3. Moving the ParallaxBackground
      4. 7.1.4. Parallax Speed Factors
      5. 7.1.5. Scrolling to Infinity and Beyond
      6. 7.1.6. Fixing the Flicker
      7. 7.1.7. Repeat, repeat, repeat
    2. 7.2. A Virtual Joypad
      1. 7.2.1. Introducing SneakyInput
      2. 7.2.2. Integrating SneakyInput
      3. 7.2.3. Touch Button to Shoot
      4. 7.2.4. Skinning the Button
      5. 7.2.5. Controlling the Action
      6. 7.2.6. Digital Controls
      7. 7.2.7. An Alternative: GPJoystick
    3. 7.3. Conclusion
  13. 8. Shoot 'em Up
    1. 8.1. Adding the BulletCache Class
    2. 8.2. What about Enemies?
    3. 8.3. The Entity Class Hierarchy
      1. 8.3.1. The EnemyEntity Class
      2. 8.3.2. The EnemyCache Class
      3. 8.3.3. The Component Classes
    4. 8.4. Shooting Things
    5. 8.5. A Healthbar for the Boss
    6. 8.6. Conclusion
  14. 9. Particle Effects
    1. 9.1. Example Particle Effects
    2. 9.2. Creating a Particle Effect the Hard Way
      1. 9.2.1. Variance Properties
      2. 9.2.2. Number of Particles
      3. 9.2.3. Emitter Duration
      4. 9.2.4. Emitter Modes
        1. 9.2.4.1. Emitter Mode: Gravity
        2. 9.2.4.2. Emitter Mode: Radius
      5. 9.2.5. Particle Position
      6. 9.2.6. Particle Size
      7. 9.2.7. Particle Direction
      8. 9.2.8. Particle Lifetime
      9. 9.2.9. Particle Color
      10. 9.2.10. Particle Blend Mode
      11. 9.2.11. Particle Texture
    3. 9.3. Introducing the Particle Designer
      1. 9.3.1. Using Particle Designer Effects
      2. 9.3.2. Sharing Particle Effects
    4. 9.4. Shoot 'em Up with Particle Effects
    5. 9.5. Conclusion
  15. 10. Working with Tilemaps
    1. 10.1. What Is a Tilemap?
    2. 10.2. Preparing Images with Zwoptex
    3. 10.3. Tiled Map Editor
      1. 10.3.1. Creating a New Tilemap
      2. 10.3.2. Designing a Tilemap
    4. 10.4. Using Orthogonal Tilemaps with Cocos2d
      1. 10.4.1. Locating Touched Tiles
      2. 10.4.2. An Exercise in Optimization and Readability
      3. 10.4.3. Working with the Object Layer
      4. 10.4.4. Drawing the Object Layer Rectangles
      5. 10.4.5. Scrolling the Tilemap
    5. 10.5. Conclusion
  16. 11. Isometric Tilemaps
    1. 11.1. Designing Isometric Tile Graphics
    2. 11.2. Isometric Tilemap Editing with Tiled
      1. 11.2.1. Creating a New Isometric Tilemap
      2. 11.2.2. Creating a New Isometric Tileset
      3. 11.2.3. Laying Down Some Ground Rules
    3. 11.3. Isometric Game Programming
      1. 11.3.1. Loading the Isometric Tilemap in Cocos2d
      2. 11.3.2. Setup Cocos2d for Isometric Tilemaps
      3. 11.3.3. Locating an Isometric Tile
      4. 11.3.4. Scrolling the Isometric Tilemap
      5. 11.3.5. This World Deserves a Better End
      6. 11.3.6. Adding a Movable Player Character
        1. 11.3.6.1. Enabling the Player to Move Behind Tiles
        2. 11.3.6.2. Moving the Player, Tile by Tile
        3. 11.3.6.3. Stop Player on Collisions
    4. 11.4. Adding More Content to the Game
    5. 11.5. Conclusion
  17. 12. Physics Engines
    1. 12.1. Basic Concepts of Physics Engines
    2. 12.2. Limitations of Physics Engines
    3. 12.3. The Showdown: Box2D vs. Chipmunk
    4. 12.4. Box2D
      1. 12.4.1. The World According to Box2D
      2. 12.4.2. Restricting Movement to the Screen
      3. 12.4.3. Converting Points
      4. 12.4.4. Adding Boxes to the Box2D World
      5. 12.4.5. Connecting Sprites with Bodies
      6. 12.4.6. Collision Detection
      7. 12.4.7. Joint Venture
    5. 12.5. Chipmunk
      1. 12.5.1. Objectified Chipmunk
      2. 12.5.2. Chipmunks in Space
      3. 12.5.3. Boxing-In the Boxes
      4. 12.5.4. Adding Ticky-Tacky Little Boxes
      5. 12.5.5. Updating the Boxes' Sprites
      6. 12.5.6. A Chipmunk Collision Course
      7. 12.5.7. Joints for Chipmunks
    6. 12.6. Conclusion
  18. 13. Pinball Game
    1. 13.1. Shapes: Convex and Counterclockwise
    2. 13.2. Working with VertexHelper
    3. 13.3. Creating the Pinball Table
      1. 13.3.1. Box2D Debug Drawing
    4. 13.4. Adding Dynamic Elements
      1. 13.4.1. The BodyNode Class
      2. 13.4.2. The Ball
        1. 13.4.2.1. Creating the Ball (Again)
        2. 13.4.2.2. Forcing the Ball to Move
      3. 13.4.3. The Bumpers
      4. 13.4.4. The Plunger
        1. 13.4.4.1. Launching the Ball on Contact
      5. 13.4.5. The Flippers
    5. 13.5. Conclusion
  19. 14. Game Center
    1. 14.1. Enabling Game Center
      1. 14.1.1. Creating Your App in iTunes Connect
      2. 14.1.2. Setting Up Leaderboards and Achievements
      3. 14.1.3. Creating a Cocos2d Xcode Project
      4. 14.1.4. Configuring the Xcode Project
      5. 14.1.5. Summary
    2. 14.2. Game Kit Programming
      1. 14.2.1. The GameKitHelper Delegate
      2. 14.2.2. Checking for Game Center Availability
      3. 14.2.3. Authenticating the Local Player
      4. 14.2.4. Block Objects
      5. 14.2.5. Receiving the Local Player's Friend List
      6. 14.2.6. Leaderboards
      7. 14.2.7. Achievements
      8. 14.2.8. Matchmaking
    3. 14.3. Conclusion
  20. 15. Out of the Ordinary
    1. 15.1. Useful Technologies
      1. 15.1.1. Social Networks
      2. 15.1.2. Socket Server Technology
      3. 15.1.3. Ads and Analytics
      4. 15.1.4. Push Notification Providers
    2. 15.2. Source Code Projects to Benefit From
      1. 15.2.1. Sapus Tongue Source Code
      2. 15.2.2. LevelSVG
      3. 15.2.3. The iPhone RPG Game Kit
      4. 15.2.4. Line-Drawing Game Starterkit
    3. 15.3. For Your Reference
    4. 15.4. Working with Publishers
    5. 15.5. Finding Freelancers
    6. 15.6. Finding Free Art and Audio
    7. 15.7. Finding the Tools of the Trade
    8. 15.8. Marketing
      1. 15.8.1. Marketing Your Game and Your Self
      2. 15.8.2. Public Relations and Press Releases
    9. 15.9. Where to Find Help
      1. 15.9.1. Cocos2d Home Page
      2. 15.9.2. Stack Exchange Network
      3. 15.9.3. Tutorials and FAQs
    10. 15.10. Famous Last Words
    11. 15.11. Conclusion

Product information

  • Title: Learn iPhone and iPad cocos2d Game Development
  • Author(s):
  • Release date: November 2010
  • Publisher(s): Apress
  • ISBN: 9781430233039