You are previewing Cocos2d-x by Example Beginner's Guide.
O'Reilly logo
Cocos2d-x by Example Beginner's Guide

Book Description

With Cocos2d-x you don’t have to be a programming whiz to be a genius at game design. This tutorial will help unleash your inner creativity with lots of fun tutorials. Get the know-how to build great cross-platform 2D games.

  • Learn to build multi-device games in simple, easy steps, letting the framework do all the heavy lifting

  • Spice things up in your games with easy to apply animations, particle effects, and physics simulation

  • Quickly implement and test your own gameplay ideas, with an eye for optimization and portability

  • Enjoy building the games as much as you will enjoy playing them

  • In Detail

    Cocos2d-x is the C++ port of arguably the most popular open source 2D framework in the world. Its predecessor was limited to the Apple family but with Cocos2d-x you can take your applications to all major app stores, with minimum extra work. Give your games a larger target audience with almost no extra hassle.

    "Cocos2d-X by Example Beginner's Guide" allows you to build your own cross platform games using all the benefits of a time tested framework, plus the elegance and simplicity of C++.

    Each of the six games developed in this book will take you further on the road to becoming an expert game developer with no fuss and plenty of fun.

    Follow six tutorials for six very different games that leverage the ease of Cocos2D-X and its quick implementation, moving from simple ideas to more advanced topics in game development.

    In easy-to-follow steps, the book teaches you how to take full advantage of the framework by adding animations and special effects, implementing a physics engine, and optimizing your games.

    Prepare your project for multiple platforms and learn how to take your game concepts to completion.

    "Cocos2d-X by Example Beginner's Guide" will present to you, in six different games, the topics necessary to build some of the most popular and fun types of games today.

    Table of Contents

    1. Cocos2d-x by Example Beginner's Guide
      1. Table of Contents
      2. Cocos2d-x by Example Beginner's Guide
      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. Conventions
        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. Errata
          3. Piracy
          4. Questions
      8. 1. Installation
        1. Download and installation
        2. Time for action – downloading and installing Cocos2d-x
          1. What just happened?
        3. Hello-x World-x
        4. Time for action – creating an application
          1. What just happened?
            1. The folder structure
            2. The iOS linkage classes
            3. The AppDelegate class
            4. The HelloWorldScene class
            5. Who begets whom
        5. Further information
        6. Time for action – running the test samples
          1. What just happened?
        7. The other tools
        8. Summary
      9. 2. You plus C++ plus Cocos2d-x
        1. Cocos2d-x – an introduction
          1. The containers
          2. The director and caches
          3. Then there is all the other stuff
          4. But you don't know C++?
        2. The interface
        3. Time for action – creating the interface
          1. What just happened?
        4. The implementation
        5. Time for action – creating the implementation
          1. What just happened?
        6. Instantiation and memory management
          1. Option 1 – use static methods
          2. Option 2 – C++, Cocos2d-x style
        7. What you get with CCObject
        8. Summary
      10. 3. Your First Game – Air Hockey
        1. Game configurations
        2. Time for action – creating your game project
          1. What just happened?
        3. Time for action – laying down the rules
          1. What just happened?
        4. Supporting retina displays
        5. Time for action – adding the image files
          1. What just happened?
        6. Time for action – adding retina support
          1. What just happened?
        7. Adding sound effects
        8. Time for action – adding the sound files
          1. What just happened?
        9. Extending CCSprite
        10. Time for action – adding GameSprite.cpp
          1. What just happened?
        11. Time for action – implementing GameSprite
          1. What just happened?
          2. Have a go hero
        12. The actual game scene
        13. Time for action – coding the GameLayer interface
          1. What just happened?
        14. Time for action – implementing init()
          1. What just happened?
        15. Time for action — handling multi-touches
          1. What just happened?
        16. Time for action – adding our main loop
          1. What just happened?
        17. Time for action – updating scores
          1. What just happened?
          2. Have a go hero
        18. Summary
      11. 4. Fun with Sprites – Sky Defense
        1. The game – Sky Defense
          1. The game settings
          2. The start project
          3. Adding screen support for a universal app
          4. Adding background music
          5. Initializing the game
        2. Using sprite sheets in Cocos2d-x
          1. Batch drawing sprites
        3. Time for action – creating a CCSpriteBatchNode
          1. What just happened?
        4. Bitmap fonts in Cocos2d-x
        5. Time for action – creating bitmap font labels
          1. What just happened?
        6. Time for action – adding the final screen sprites
          1. What just happened?
        7. Time for action – creating our object pools
          1. What just happened?
        8. CCActions in a nutshell
        9. Time for action – creating actions with Cocos2d-x
          1. What just happened?
        10. Animating a sprite in Cocos2d-x
        11. Time for action – creating animations
          1. What just happened?
        12. Time to make our game tick!
        13. Time for action – handling touches
          1. What just happened?
        14. Time for action – starting and restarting the game
          1. What just happened?
        15. Time for action – updating the game
          1. What just happened?
        16. Time for action – retrieving objects from the pool
          1. What just happened?
        17. Play the game!
          1. Pop quiz – sprites and actions
        18. Summary
      12. 5. On the Line – Rocket Through
        1. The game – Rocket Through
          1. The game settings
          2. Play first, work later
          3. The start project
          4. Screen settings
        2. So what are particles?
        3. Time for action – creating particle systems
          1. What just happened?
        4. Creating the grid
        5. Drawing primitives in Cocos2d-x
        6. Time for action – let's do some drawing!
          1. What just happened?
        7. The Rocket sprite
        8. Time for action – updating our Rocket
          1. What just happened?
        9. Time for Action – handling touches
          1. What just happened?
        10. The game loop
        11. Time for action – adding the main loop
          1. What just happened?
        12. Kill and reset
        13. Time for action – adding our resets and kills
          1. Have a go hero
        14. Summary
      13. 6. Quick and Easy Sprite – Victorian Rush Hour
        1. The game – Victorian Rush Hour
        2. The game settings
        3. Rapid prototyping with Cocos2d-x
        4. Time for action – creating placeholder sprites
          1. What just happened?
        5. The Player object
        6. The Block object
        7. The Terrain object
        8. Time for action – coding the player
          1. What just happened?
        9. Time for action – coding the Block object
          1. What just happened?
          2. Planning the Terrain class
          3. Building the Terrain object
        10. Time for action – initialising our Terrain class
          1. What just happened?
        11. Time for action – initializing our Blocks
          1. What just happened?
        12. Time for action – moving and resetting
          1. What just happened?
        13. Platform collision logic
        14. Time for action – adding collision detection
          1. What just happened?
        15. Adding the controls
        16. Time for action – handling touches
          1. What just happened?
        17. Time for action – coding the main loop
          1. What just happened?
        18. Summary
      14. 7. Adding the Looks – Victorian Rush Hour
        1. Victorian Rush Hour – the game
          1. New sprites
          2. Animations
        2. Texturing our buildings with CCSprites
        3. Time for action – texturing the buildings
          1. What just happened?
        4. Containers within containers
        5. Creating a parallax effect
        6. Time for action – creating a parallax effect
          1. What just happened?
        7. Adding a menu to our game
        8. Time for action – creating CCMenu and CCMenuItem
          1. What just happened?
        9. Adding a tutorial to our game
        10. Time for action – adding a tutorial
          1. What just happened?
        11. Summary
      15. 8. Getting Physical – Box2D
        1. Creating a Box2D project with Cocos2d-x
        2. Time for action – preparing the basic template
          1. What just happened?
        3. So what is a physics engine?
          1. Meet Box2D
          2. Meet the world
          3. Running the simulation
          4. No CCObjects in Box2D
          5. Meet the bodies
        4. Our game – MiniPool
          1. Game settings
          2. CCSprite + b2Body = b2Sprite
          3. Creating the pool table
          4. Creating edges
          5. Creating the ball objects
          6. Creating collision filters
          7. Creating the cue ball
          8. Creating a contact listener
          9. The game controls
        5. Time for action – adding the touch events
          1. What just happened?
          2. The main loop
        6. Time for action – adding the main loop
          1. What just happened?
          2. Adding a timer to our game
        7. Time for action – creating a timer
          1. What just happened?
          2. Have a go hero
          3. Pop quiz
        8. Summary
      16. 9. The Last Game – Eskimo
        1. The game – Eskimo
          1. The game settings
          2. How the game is organized
        2. Using CCScenes in Cocos2d-x
        3. Time for action – creating a CCScene transition
          1. What just happened?
        4. Time for action – creating transitions with a singleton CCLayer
          1. What just happened?
        5. Loading external data from a .plist file
        6. Time for action – creating a .plist file
          1. What just happened?
          2. Loading the level data
        7. Time for action – retrieving data from the .plist file
          1. What just happened?
        8. Saving game data
        9. Time for action – storing the completed levels
          1. What just happened?
        10. Using notifications in your game
        11. Time for action – using CCNotificationCenter
          1. What just happened?
        12. Using the accelerometer
        13. Time for action – reading accelerometer data
          1. What just happened?
        14. Reusing b2Bodies
        15. Time for action – changing a b2Body fixture
          1. What just happened?
          2. Have a go hero
        16. Summary
      17. 10. Code Once. Retire.
        1. First, a word on versions and requirements
          1. Requirements
          2. Further steps
        2. Time for action – creating an Android project with Cocos2d-x
          1. What just happened?
        3. Time for action – compiling the code
          1. What just happened?
        4. Using Eclipse
        5. Time for action – installing the C++ compiler
          1. What just happened?
        6. Time for action – adding the Cocos2d-x library to Eclipse
          1. What just happened?
        7. Time for action – opening the project in Eclipse
          1. What just happened?
          2. Running the application
        8. Compiling C++ code in Eclipse
        9. Time for action – compiling our C++ code
          1. What just happened?
        10. Creating a hybrid project
        11. Time for action – creating a hybrid Cocos2d-x project
          1. What just happened?
        12. Creating a Box2D hybrid project
        13. Time for action – creating a Box2D project
          1. What just happened?
        14. Developing a hybrid game
        15. Summary
      18. A. Vector Calculations with Cocos2d-x
        1. What are vectors?
          1. The vector methods
        2. Using ccp helper methods
          1. Rotating the rocket around a point
          2. Using the dot product of vectors
          3. Moving from pixel-based speed to angular-based speed
      19. B. Pop Quiz Answers
        1. Chapter 4, Fun with Sprites – Sky Defense
          1. Pop quiz – sprites and actions
        2. Chapter 8, Getting Physical – Box2D
          1. Pop quiz – Box2D
      20. Index