You are previewing Learning Cocos2d-x Game Development.
O'Reilly logo
Learning Cocos2d-x Game Development

Book Description

Learn cross-platform game development with Cocos2d-x

In Detail

Cocos2d-x is one of the most popular cross-platform 2D game engines. It is packed with powerful features that set it apart from other game engines. With so many languages and operating systems, Cocos2d-x provides a one-stop solution for developing games for the operating system of your choice using the language you are most comfortable with. Starting from the basics, this book will show you how to display content on the screen and make it interact as well as move around with various control mechanisms such as actions, accelerometer, and tap onscreen buttons. You will learn about the mechanics of collision detection, their advantages and disadvantages, and how to keep track of the score. You will then create a gameplay cycle, use third-party tools to expedite the development process, and distribute the game through the App Store.

By working through the carefully designed chapters of the book, you will master Cocos2d-x and the various tools so that you can use these skills to make a complete game or a quick prototype.

What You Will Learn

  • Configure and create a Cocos2d-x project on Windows
  • Understand the basics of Cocos2d-x classes such as CCScene, CCLayer, and CCSprite
  • Develop different control schemes using buttons, a gyroscope, and a custom touch area
  • Implement various methods for collision detection such as circle collision and bounding box collision
  • Discover how to add and remove objects from the screen and update the score as well as Gameover condition
  • Get to grips with the tools used to create spritesheets as well as custom fonts and design particles
  • Integrate ads and in-app purchases in the game to monetize the game
  • 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 If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.

    Table of Contents

    1. Learning Cocos2d-x Game Development
      1. Table of Contents
      2. Learning Cocos2d-x Game Development
      3. Credits
      4. About the Author
      5. Acknowledgments
      6. About the Reviewers
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      8. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      9. 1. Getting Started
        1. Downloading and installing Visual Studio
        2. Downloading and installing the Windows Phone SDK
        3. Downloading and installing Python
        4. Downloading Cocos2d-x
        5. Creating a new project
        6. Coordinate system
        7. Basic classes of Cocos2d-x
        8. Project breakup
        9. Running the project on multiple platforms
          1. Running the project on Windows (desktop mode)
          2. Running the project on Windows RT (tile mode)
          3. Running the project on the iPhone simulator using Xcode
          4. Running the project on an Android simulator using Eclipse
        10. Summary
      10. 2. Displaying the Hero and Controls
        1. First things first
        2. Displaying the background image
        3. Character movement
        4. Enabling the touch function
        5. Enabling multitouch
        6. Movement with touches
        7. Movement with the accelerometer
        8. Custom controls
        9. Summary
      11. 3. Enemies and Controls
        1. Creating the enemy class
          1. Adding the enemy movement
        2. Adding the gameplay layer
        3. Creating the projectile class
        4. Adding hero controls
        5. Summary
      12. 4. Collision Detection and Scoring
        1. Theory of collision detection
          1. Circular collision
          2. Bounding box collision
          3. Pixel perfect collision
          4. Other collision detection methods
        2. Coding collision detection
        3. Keeping track of the score and the game over condition
        4. Storing high scores
        5. Summary
      13. 5. HUD, Parallax Background, and the Pause Button
        1. Texts and fonts
          1. Literra
          2. Bitmap font generator
          3. GlyphDesigner
        2. Creating the HUD layer and displaying as well as updating scores
        3. Creating the pause button and showing the pause screen
        4. Implementing pause and resuming the game
        5. Adding the scrolling layer class
        6. Creating the parallax scrolling layer
        7. Summary
      14. 6. Animations
        1. Animation basics
          1. Spritesheet animation
          2. Skeletal animation
        2. TexturePacker
          1. The display section
          2. The Geometry section
          3. The Layout section
          4. Advanced features
        3. Creating a spritesheet for the player
        4. Coding the player animation
        5. Creating and coding enemy animation
        6. Creating the skeletal animation
        7. Coding the player walk cycle
        8. Summary
      15. 7. Particle Systems
        1. What is a particle system?
        2. Cocos2d-x's inbuilt particle system
        3. Adding the gun muzzle particle system
          1. Particle designing
          2. Particle Designer
            1. Emitter Configuration
            2. Particle Configuration
            3. Color Settings
            4. Texture Settings
          3. Particle2dx
            1. Motion
            2. Color&Shape
            3. Template
            4. InOut
            5. Background
        4. Adding an explosion particle system
        5. Adding particles for jetpack when a player moves upwards
        6. Creating your own particle system
        7. Summary
      16. 8. Adding Main and Option Menu Scenes
        1. Creating the main menu scene
        2. Loading the menu scene at start of the app
        3. Creating the Options scene
        4. Changing the name of the app
        5. Summary
      17. 9. Adding Sounds and Effects
        1. Audio in Cocos2d-x
        2. Adding looped background music
        3. Adding sound effects
        4. Adding the mute button
        5. Summary
      18. 10. Publishing to the Windows Phone Store
        1. A look at the Windows Phone Store
        2. Creating the store account
        3. Preparing/creating the app
        4. Creating the app and setting pricing
        5. Uploading the XAP file, icons, and screenshots for review
        6. Summary
      19. 11. Porting, References, and Final Remarks
        1. Running the game on the Windows desktop
        2. Running the game on the Android simulator using the Eclipse IDE
        3. Running on the BlackBerry simulator using the Momentics IDE
        4. Running on an iOS simulator using Xcode
        5. Additional learning resources
          1. Cocos2d-x
          2. Cocos2d-Swift
        6. Final remarks and a thank you note
      20. Index