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

Book Description

Unleash your inner creativity and learn how to build great cross-platform 2D games with the popular Cocos2d-x framework

In Detail

Upgraded and updated, the powerful and popular open source framework Cocos2d-x is better than ever. Through step-by-step tutorials, you'll learn how to take complete advantage of the framework. You'll learn how to add animations and special effects, implement a physics engine, optimize your games, prepare a project for multiple devices, and develop game ideas from the test version to a finished project.

Most importantly, this book provides you with the accumulated knowledge of thousands of game developers, all packed into one easy-to-use and proven framework that will save time and strenuous thinking!

What You Will Learn

  • Add time-saving and fun-looking animations to your projects

  • Make your games look cooler with particle effects

  • Draw lines, circles, and other primitives on the screen

  • Create place holder sprites to quickly test your game ideas

  • Load external data into your games

  • Create projects and deploy them to iOS and Android

  • Prepare your game for a variety of screen sizes and resolutions

  • Use the CocosIDE and the Lua bindings to develop a 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 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-x by Example Beginner's Guide Second Edition
      1. Table of Contents
      2. Cocos2d-x by Example Beginner's Guide Second Edition
      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. Conventions
        7. Reader feedback
        8. Customer support
          1. Downloading the example code
          2. Downloading the color images of this book
          3. Errata
          4. Piracy
          5. Questions
      8. 1. Installing Cocos2d-x
        1. Downloading and installing Cocos2d-x
        2. Time for action – downloading, downloading, downloading
          1. What just happened?
        3. Time for action – installing Cocos2d-x
          1. What just happened?
        4. Hello-x World-x
        5. Time for action – creating an application
          1. What just happened?
        6. Time for action – deploying to Android
          1. What just happened?
          2. The folder structure
          3. The iOS linkage classes
          4. The AppDelegate class
          5. The HelloWorldScene class
          6. Who begets whom?
        7. Finding more reference material
        8. Time for action – running the test samples
          1. What just happened?
        9. The other tools
        10. Summary
      9. 2. You Plus C++ Plus Cocos2d-x
        1. Cocos2d-x – an introduction
          1. Containers
          2. The Director and cache classes
          3. The other stuff
          4. Do you know C++?
        2. The class interface
        3. Time for action – creating the interface
          1. What just happened?
        4. The class implementation
        5. Time for action – creating the implementation
          1. What just happened?
        6. Instantiating objects and managing memory
          1. Using static methods
          2. The C++ and Cocos2d-x style
        7. What you get with Ref
        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 Sprite
        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 multitouches
          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?
        18. Time for action – running the game in Android
          1. What just happened?
          2. Have a go hero
        19. 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 SpriteBatchNode
          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. Actions 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!
        18. Time for action – running the game in Android
          1. What just happened?
          2. Pop quiz – sprites and actions
        19. 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 sprite
          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. What just happened?
        14. Time for action – running the game in Android
          1. What just happened?
          2. Have a go hero
        15. 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 – initializing our Terrain class
          1. What just happened?
        11. Time for action – initializing our Blocks object
          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 sprites
        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 Menu and MenuItem
          1. What just happened?
        9. Adding a tutorial to our game
        10. Time for action – adding a tutorial
          1. What just happened?
        11. Time for action – running the game in Android
          1. What just happened?
        12. Summary
      15. 8. Getting Physical – Box2D
        1. Building a Box2D project with Cocos2d-x
        2. Time for action – using debug draw in your Box2D project
          1. What just happened?
        3. So what is a physics engine?
          1. Meeting Box2D
          2. Meeting the world
          3. Running the simulation
          4. No Ref objects in Box2D
          5. Meeting the bodies
        4. Our game – MiniPool
          1. Game settings
          2. Sprite plus b2Body equal to b2Sprite
          3. Creating the pool table
          4. Creating edges
          5. Creating the ball objects
          6. Creating collision filters
          7. Creating the cue
          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?
        8. Time for action – running the game in Android
          1. What just happened?
          2. Have a go hero
          3. Pop quiz
        9. Summary
      16. 9. On the Level – Eskimo
        1. The game – Eskimo
          1. The game settings
          2. Organizing the game
        2. Using scenes in Cocos2d-x
        3. Time for action – creating a scene transition
          1. What just happened?
        4. Time for action – creating transitions with a singleton Layer class
          1. What just happened?
        5. Loading external data from a .plist file
        6. Time for action – creating a .plist file
          1. What just happened?
        7. Loading the level data
        8. Time for action – retrieving data from the .plist file
          1. What just happened?
        9. Saving game data
        10. Time for action – storing the completed levels
          1. What just happened?
        11. Using events in your game
        12. Time for action – using the event dispatcher
          1. What just happened?
        13. Using the accelerometer
        14. Time for action – reading accelerometer data
          1. What just happened?
        15. Reusing b2Bodies
        16. Time for action – changing a b2Body fixture
          1. What just happened?
        17. Time for action – running the game in Android
          1. What just happened?
          2. Have a go hero
        18. Summary
      17. 10. Introducing Lua!
        1. So what is Lua like?
          1. Debugging in Lua – the knights who say nil
        2. The game – Stone Age
        3. Time for action – creating or importing a project
          1. What just happened?
        4. Time for action – setting up our screen resolution
          1. What just happened?
        5. Time for action – creating a menu scene
          1. What just happened?
        6. Time for action – creating our game scene
          1. What just happened?
        7. Time for action – building the gems
          1. What just happened?
        8. Time for action – changing the grid with GridController
          1. What just happened?
        9. Time for action – swapping the gems and looking for matches
          1. What just happened?
        10. Time for action – collapsing the grid and repeating
          1. What just happened?
        11. Time for action – animating matches and collapses
          1. What just happened?
        12. Time for action – publishing the game with the Cocos IDE
          1. What just happened?
        13. 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
      20. Index