You are previewing Learning iPhone Game Development with Cocos2D 3.0.
O'Reilly logo
Learning iPhone Game Development with Cocos2D 3.0

Book Description

Harness the power of Cocos2D to create your own stunning and engaging games for iOS

In Detail

Cocos2D-iPhone (Cocos2D-Swift) is a robust yet simple-touse 2D game framework for iPhone. If you are just starting with game programming, Cocos2D will enable you to make your first game in no time. Even if you are a seasoned game developer, you will still be able to benefit from what Cocos2D offers.

This book will set you on the fast-track to game development with Cocos2D for iPhone. You will start by reviewing the basic classes and hierarchy, dive deep into animations and game flow, and finish by creating a complete game with UI using some advanced techniques.

You will begin the book with an empty Cocos2D project and build on it until you end up with a complete game. The book will teach you how to work on game logic, handling user input, controlling the character, and playing audio. Later, in the final part of the book, we'll have a working game on our hands, and we'll see how we can improve the game further

What You Will Learn

  • Install Cocos2D and create projects using Cocos2D Xcode templates
  • Understand the Cocos2D architecture and its main classes
  • Render images and text, move and animate them
  • Control your game using touches and a gyroscope
  • Create a user interface and navigate between game screens
  • Use the physics engine to apply forces and detect collisions
  • Add sounds and music and change playback properties
  • Integrate your game with Game Center and make In-App purchases
  • 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. Learning iPhone Game Development with Cocos2D 3.0
      1. Table of Contents
      2. Learning iPhone Game Development with Cocos2D 3.0
      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. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Sections
        5. Time for action – heading
          1. What just happened?
          2. Pop quiz – heading
          3. Have a go hero – heading
        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. All About Cocos2D
        1. Game engines
          1. So what is a game engine?
          2. So what is this all about?
        2. Why Cocos2D?
          1. Cocos2D is easy
          2. Cocos2D is free
          3. Cocos2D is popular
          4. Cocos2D is open source
          5. Want more?
        3. Games created with Cocos2D
          1. BADLAND
          2. Feed Me Oil 2
          3. Lep's World 2
          4. Other games
        4. Summary
      9. 2. Hello Cocos2D
        1. Starting with Xcode
        2. Integrating Cocos2D with Xcode
        3. Time for action – downloading and installing Cocos2D
          1. What just happened?
        4. Creating a Hello World project
        5. Time for action – creating a new project from a template
          1. What just happened?
          2. Testing your projects on a device and simulator
        6. Time for action – running the project on the simulator
          1. What just happened?
        7. Modifying the project
        8. Time for action – creating a new scene
          1. What just happened?
        9. Time for action – displaying the world
          1. What just happened?
        10. Time for action – displaying the welcome label
          1. What just happened?
          2. Have a go hero
        11. Reviewing Cocos2D distribution
        12. Time for action – running tests
          1. What just happened?
          2. Pop quiz – hello quiz
        13. Summary
      10. 3. Cocos2D – Under the Hood
        1. Reviewing Cocos2D
          1. Have Cocos2D your way
            1. Rendering on the screen and the birth of CCNode
            2. Organizing the game with CCScene
            3. Children of CCNode
            4. Back to real Cocos2D
          2. Cocos2D game life cycle
            1. Reviewing the AppDelegate class
            2. Cocos2D configuration options
            3. Further life of the game
          3. Reviewing the CCDirector class
          4. Pop quiz – under the hood
        2. Summary
      11. 4. Rendering Sprites
        1. Creating the game project
        2. Time for action – creating the Cocohunt Xcode project
          1. What just happened?
        3. Time for action – creating GameScene
          1. What just happened?
        4. Adding sprites to your game
        5. Time for action – adding the background sprite
          1. What just happened?
            1. Adding the background image to the Xcode project
            2. Adding a background sprite to the GameScene
        6. Time for action – adding the player character
          1. What just happened?
            1. Preparations step
            2. Adding images to the hunter character
            3. Adding the hunter object to our game scene
        7. Time for action – fixing z-order
          1. What just happened?
        8. Adding more sprites and moving them
        9. Time for action – adding birds
          1. What just happened?
        10. Time for action – making the bird move
          1. What just happened?
            1. Meeting the update: method
            2. Reviewing bird movement in the update: method
        11. Understanding debug FPS labels
          1. Have a go hero
        12. Spritesheets and animation
        13. Time for action – creating a spritesheet
          1. What just happened?
        14. Time for action – modifying the game to use spritesheets
          1. What just happened?
            1. Changes in GameScene
            2. Changes in the Hunter and Bird classes
            3. Understanding spritesheet's limitations
            4. Automatic batching
        15. Time for action – animating the birds
          1. What just happened?
          2. Pop quiz – sprites
        16. Summary
      12. 5. Starting the Action
        1. Making the hunter aim and shoot
        2. Time for action – handling touches
          1. What just happened?
        3. Time for action – aiming at the touch position
          1. What just happened?
        4. Time for action – shooting the arrow
          1. What just happened?
        5. Adding more birds to the GameScene class
        6. Time for action – adding more birds
          1. What just happened?
        7. Time for action – detecting if the arrow hits the bird
          1. What just happened?
        8. Winning, losing, and other states
        9. Time for action – using states for the bird's life cycle
          1. What just happened?
        10. Time for action – animating the shooting and limiting the shooting rate
          1. What just happened?
        11. Time for action – winning or losing the game
          1. What just happened?
        12. Improving the gameplay
        13. Time for action – limiting the aiming range
          1. What just happened?
        14. Time for action – alternative control using a gyroscope
          1. What just happened
          2. Have a go hero
          3. Pop quiz – geometry and actions
        15. Summary
      13. 6. Rendering Text
        1. The easy way – CCLabelTTF
        2. Time for action – adding labels
          1. What just happened?
        3. Time for action – updating labels
          1. What just happened?
        4. Using bitmap fonts for better performance
          1. Choosing a bitmap font generator
        5. Time for action – creating a bitmap font using Glyph Designer
          1. What just happened?
          2. Using the bitmap font in the game
        6. Time for action – adding hit points
          1. What just happened?
        7. Time for action – adding the win and lose labels
          1. What just happened?
          2. Have a go hero
          3. Pop quiz – labels
        8. Summary
      14. 7. Animations and Particle Systems
        1. Using frame-based animation
        2. Time for action – exploding coconut
          1. What just happened?
            1. Coconut explosion animation
            2. Easing actions
            3. Adding a splash screen
            4. When to use frame-based animation
        3. Animating using actions
        4. Time for action – hitting the bird animation
          1. What just happened?
        5. Skeletal animation
        6. Creating particle systems for advanced effects
        7. Time for action – adding the feathers explosion
          1. What just happened?
        8. Time for action – adding a fire to the scene
          1. What just happened?
        9. Time for action – using Particle Designer
          1. What just happened?
          2. Have a go hero
          3. Pop quiz – animations and particle systems
        10. Summary
      15. 8. Adding Sound Effects and Music
        1. Creating AudioManager and playing sound effects
        2. Time for action – adding the AudioManager class
          1. What just happened?
        3. Time for action – finding and playing our first sound effect
          1. What just happened?
        4. Time for action – playing the remaining sound effects
          1. What just happened?
          2. Have a go hero
        5. Music and background sounds
        6. Time for action – adding background sounds
          1. What just happened?
        7. Time for action – adding music
          1. What just happened?
        8. Enhancing Cocohunt sound effects
        9. Time for action – preloading sound effects
          1. What just happened?
        10. Time for action – playing a sound at position
          1. What just happened?
          2. Have a go hero
          3. Pop quiz – playing audio
        11. Summary
      16. 9. User Interface and Navigation
        1. Using buttons
        2. Time for action – adding menu buttons
          1. What just happened?
            1. Adding buttons
            2. Using normalized coordinates
            3. Replacing the currently running scene
        3. Time for action – toggling sound and music
          1. What just happened?
        4. Time for action – storing settings in NSUserDefaults
          1. What just happened?
          2. Have a go hero
        5. Navigating between scenes
        6. Time for action – pushing AboutScene
          1. What just happened?
            1. Displaying AboutScene using the pushScene: method
            2. Using 9-slice scaling on AboutScene
            3. Creating rectangular multiline labels
        7. Time for action – using more transitions
          1. What just happened?
        8. Time for action – using the scroll view to select levels
          1. What just happened?
          2. Have a go hero
        9. Creating modal dialogs and using text input
        10. Time for action – pausing the game with a pause dialog
          1. What just happened?
            1. Using a background image as a container for UI elements
            2. Swallowing touches
            3. Pausing and resuming the game
        11. Time for action – restarting and exiting the game
          1. What just happened?
        12. Time for action – displaying stats when losing and winning
          1. What just happened?
        13. Entering and displaying highscores
        14. Time for action – displaying highscores with CCTableView
          1. What just happened?
        15. Time for action – using the text field
          1. What just happened?
          2. Have a go hero
          3. Pop quiz
        16. Summary
      17. 10. Physics
        1. Creating a physics world
        2. Time for action – creating a game level with physics
          1. What just happened?
            1. Understanding physics bodies
            2. Linking physics bodies with Cocos2D nodes
        3. Time for action – adding ground to the scene
          1. What just happened?
          2. Have a go hero
        4. Time for action – adding the hunter
          1. What just happened?
            1. Understanding the fixedUpdate: method
        5. Time for action – fixing the hunter movement
          1. What just happened?
        6. Detecting and filtering collisions
        7. Time for action – detecting and ignoring collisions
          1. What just happened?
            1. Sensors
        8. Time for action – filtering collisions using a collision mask
          1. What just happened?
        9. Time for action – filtering collisions using collision groups
          1. What just happened?
        10. Applying forces and impulses and using joints
        11. Time for action – launching stones
          1. What just happened?
            1. Impulses versus forces
          2. Have a go hero
        12. Time for action – adding angry birds
          1. What just happened?
            1. Creating the PhysicsBird class and giving it the stone
            2. The PhysicsBird class – using joints and applying force
          2. Have a go hero
          3. Pop quiz – physics
        13. Summary
      18. 11. Working with Tile Maps
        1. Creating tile maps
        2. Time for action – creating a tileset
          1. What just happened?
        3. Time for action – creating a tile map
          1. What just happened?
        4. Time for action – creating the Retina version of the tile map
          1. What just happened?
        5. Using the tile maps
        6. Time for action – creating TilemapScene
          1. What just happened?
        7. Time for action – moving and following the bird
          1. What just happened?
        8. Time for action – using parallax scrolling
          1. What just happened?
          2. Have a go hero
          3. Pop quiz – tile maps
        9. Summary
      19. A. Pop Quiz Answers
        1. Chapter 2, Hello Cocos2D
          1. Pop quiz – hello quiz
        2. Chapter 3, Cocos2D – Under the Hood
          1. Pop quiz – under the hood
        3. Chapter 4, Rendering Sprites
          1. Pop quiz – sprites
        4. Chapter 5, Starting the Action
          1. Pop quiz – geometry and actions
        5. Chapter 6, Rendering Text
          1. Pop quiz – labels
        6. Chapter 7, Animations and Particle Systems
          1. Pop quiz – animations and particle systems
        7. Chapter 8, Adding Sound Effects and Music
          1. Pop quiz – playing audio
        8. Chapter 9, User Interface and Navigation
          1. Pop quiz
        9. Chapter 10, Physics
          1. Pop quiz – physics
        10. Chapter 11, Working with Tile Maps
          1. Pop quiz – tile maps
      20. Index