O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Cocos2d Game Development Blueprints

Book Description

Design, develop, and create your own successful iOS games using the Cocos2d game engine

In Detail

Cocos2d is one of the most popular 2D game engines for the iOS platform. It is packed with powerful features that set it apart from other game engines. It can be used to build games, apps, and other cross-platform GUI-based interactive programs.

This practical guide will develop your skills in designing and developing iOS games across several genres. You will start with managing collisions through building a horizontal scroll game for both iPhone and iPad, you will then go through building a shooting game. After that, you will learn how to use the accelerometer to control movement, load particle systems such as explosions, draw primitives, and create parallax effects. We also cover essential elements of the Cocos2d package including sprite sheets, multiple image file loading to animate a sprite, building physics behavior with Chipmunk, using filters and listeners, and providing powerful AI, non-playable characters, and pathfinder algorithms with a cool tower defence game.

What You Will Learn

  • Load and control sprites, labels, sounds, and geometrical primitives efficiently to build the core of a game
  • Simulate movement by implementing the parallax effect and running animations
  • Implement turn-based game logic including Game Center
  • Create both iPad-only and universal versions of your games
  • Control your game using touches, an accelerometer, or a virtual game pad
  • Build menus and tutorials and define some artificial intelligence to non-played characters

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Table of Contents

  1. Cocos2d Game Development Blueprints
    1. Table of Contents
    2. Cocos2d Game Development Blueprints
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    7. Preface
      1. Cocos2d v3.0
        1. Pure Objective-C
        2. ARC
        3. CCDirector
        4. CCLayer
        5. CCArray
        6. OALSimpleAudio
        7. CCAction
        8. CCActionCallBlock
        9. Sequences
        10. Schedule update
        11. Enabling touches
        12. Accelerometer events
        13. Physics
      2. What this book covers
      3. What you need for this book
      4. Who this book is for
      5. Conventions
        1. 1-star challenge – accurate collision detection
      6. Reader feedback
      7. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    8. 1. Sprites, Sounds, and Collisions
      1. Creating a new Cocos2d project
      2. Run Xcode Run
        1. Understanding the default project
      3. CCNode
      4. Your first game – RunYetiRun
        1. Creating the CCScene class
        2. Adding the first CCSprite class
        3. Anchor points
        4. Placing things in context
        5. Time for CCAction
        6. Actions under control
        7. Throwing some snowballs
        8. Rolling down the hill
        9. Managing collisions
        10. Adding labels
          1. CCLabelTTF
        11. Updating labels
        12. Making some noise
          1. OALSimpleAudio
          2. Voice memos
          3. Audacity
          4. GarageBand
          5. Audio resources
          6. Playing audio files
        13. Game over
      5. 1-star challenge – accurate collision detection
        1. The solution
      6. 2-star challenge – having three lives
        1. The solution
      7. Summary
    9. 2. Explosions and UFOs
      1. Handling the accelerometer input
        1. Linking the CoreMotion framework
        2. onEnter and onExit
        3. Converting accelerometer input into movements
        4. Calibrating the accelerometer
      2. Implementing the parallax effect in Cocos2d
        1. CCParallaxNode
      3. Particle systems
        1. CCParticleSystem
        2. CCParticleSystem modes
          1. CCParticleSystemModeGravity
          2. CCParticleSystemModeRadius
          3. Common properties
        3. Particle Designer
      4. Extending CCSprite
        1. Shooting some lasers
        2. When UFOs collide
      5. 2-star challenge – create explosions
        1. The solution
        2. The attack of the aliens
      6. Drawing and coloring
        1. Drawing the life bar
      7. 1-star challenge – collision detection between Dr. Fringe and the UFO
        1. The solution
      8. Summary
    10. 3. Your First Online Game
      1. Getting started with our project
      2. Initializing the game
      3. Creating labels with CCLabelBMFont
        1. Littera
      4. CCActions in depth
      5. Drag, drop, and scale
      6. Game Center
        1. Configuring Game Center in iTunes Connect
        2. Configuring the game in Xcode
        3. Checking Game Center's availability
        4. Authenticating the player
        5. Turn-based games
        6. The first turn
        7. Passing the turn
        8. Receiving the turn
          1. Fighting cards
          2. Labels for life points
          3. Match over
          4. Viewing the status when it's not our turn
      7. Summary
    11. 4. Beat All Your Enemies Up
      1. Creating an iPad-only game
        1. Image sizes and names
      2. Developing virtual game controls
      3. Moving the zombie
      4. CCSpriteBatchNode
      5. Texture atlases
        1. Creating texture atlases with TexturePacker
        2. Loading texture atlases with Cocos2d
      6. Creating your first animation
      7. 3-star challenge – hitting the air
        1. The solution
      8. Creating the zombie class
      9. Creating the human enemies class
      10. Keeping the main character in view
      11. Taking human decisions
      12. Drawing a life bar
      13. Detecting collisions with enemies
      14. 2-star challenge – enemies' life bar
      15. Game over
      16. Summary
    12. 5. Scenes at the Highest Level
      1. Initializing the game
      2. Developing a tutorial for our game
      3. Storing data using NSUserDefault
      4. Loading data from external files
      5. Transitions
      6. 3-star challenge – create a map scene
      7. Summary
    13. 6. Physics Behavior
      1. Physics engines
      2. Game physics in Cocos2d
      3. Introducing Chipmunk
        1. CCPhysicsNode
        2. CCPhysicsBody
      4. Creating your first physics
        1. CCPhysicsShape
      5. Creating sprites with physics
      6. Defining shapes
        1. PhysicsEditor
          1. Defining shapes
          2. Loading PhysicsEditor shapes in Xcode
      7. Advanced collision detection with Chipmunk
        1. CCPhysicsBody and CCPhysicsShape properties
        2. CCPhysicsCollisionDelegate
      8. Creating a snooker game with Chipmunk
        1. Setting the snooker table
        2. Configuring the snooker balls
        3. Hitting the cue ball
        4. Managing collisions between snooker bodies
      9. Summary
    14. 7. Jump and Run
      1. Initializing the game
      2. Configuring a varied scene
      3. Scrolling the background and blocks
      4. Coding custom physics
        1. Jumping over the platforms
      5. Adding a menu to the game
      6. 2-star challenge – adding pinecones to the scene
        1. The solution
      7. 1-star challenge – adding a score label
        1. The solution
      8. Summary
    15. 8. Defend the Tower
      1. Initializing the game
      2. Developing a pathfinding algorithm
        1. Following the path
      3. Predefining defensive positions
      4. Placing defenses
      5. Giving AI to the defenses
      6. Sharing information between nodes
      7. Loading waves of enemies
      8. 2-star challenge – adding explosions
      9. 3-star challenge – upgrading defenses
      10. Summary
    16. Index