You are previewing Cocos2d-x Cookbook.
O'Reilly logo
Cocos2d-x Cookbook

Book Description

Over 50 hands-on recipes to help you efficiently administer and maintain your games with Cocos2d-x

About This Book

  • Build exciting games, apps, and other cross-platform GUI based interactive programs with Cocos2d-x

  • Explore the nitty-gritty of the latest Cocos2d-x on the block, version 3.6

  • A step-by-step guide that shows you the functionalities of Cocos2d-x followed by an explanation of how they work

  • Who This Book Is For

    If you are a game developer and want to learn more about cross-platform game development in Cocos2d-x, then this book is for you. Knowledge of C++, Xcode, Eclipse, and how to use commands in the terminal are prerequisites for this book.

    What You Will Learn

  • Install and set up Cocos2d-x for your development environment

  • Build, test, and release game applications for iOS and Android

  • Develop your games for multiple platforms

  • Customize Cocos2d-x for your games

  • Use a physical engine in your games

  • Save and load text, JSON, XML, or other formats

  • Explore the brand new features of Cocos2d-x

  • In Detail

    Cocos2d-x is a suite of open source, cross-platform game-development tools used by thousands of developers all over the world. Cocos2d-x is a game framework written in C++, with a thin platform-dependent layer. Completely written in C++, the core engine has the smallest footprint and the fastest speed of any other game engine, and is optimized to be run on all kinds of devices.

    You will begin with the initial setup and installation of Cocos2d before moving on to the fundamentals needed to create a new project. You will then explore and create the sprites, animations, and actions that you will include in the game. Next you will look at strings and create labels, including a label with True Type Font (TTF) font support.

    Later, you will learn about layer and scene creation and transition. Then you will create the GUI parts essential for a game, such as buttons and switches. After that, you will breathe life into the game with background music and sound effects using the all new Cocos2d-x audio engine. You will then discover how to manage resource files and implement processes that depend on the operating system.

    Finally, you will polish your game with physics such as gravity and elevation, learn about tools that will help you make games more robust and stable, and get to know best practices to improve the game you have developed.

    Style and approach

    This book is an easy-to-follow guide with ample recipes to help you better understand Cocos2d-x.

    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 code file.

    Table of Contents

    1. Cocos2d-x Cookbook
      1. Table of Contents
      2. Cocos2d-x Cookbook
      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
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        5. Conventions
        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. Getting Started with Cocos2d-x
        1. Introduction
        2. Setting up our Android Environment
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Installing Cocos2d-x
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        4. Using the Cocos command
          1. How to do it...
          2. How it works...
          3. There's more...
        5. Building the project using Xcode
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Building the project using Eclipse
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        7. Implementing multi-resolution support
          1. How to do it…
          2. How it works…
        8. Preparing your original game
          1. How to do it…
          2. How it works…
      9. 2. Creating Sprites
        1. Introduction
        2. Creating sprites
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Getting the sprite's position and size
          1. How to do it...
          2. How it works...
          3. There's more...
            1. Setting anchor points
            2. Rectangle
          4. See also
        4. Manipulating sprites
          1. How to do it...
            1. Rotate
            2. Scale
            3. Skew
            4. Color
            5. Opacity
            6. Visibility
          2. How it works...
        5. Creating animations
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Creating actions
          1. How to do it...
            1. Move
            2. Scale
            3. Jump
            4. Rotate
            5. Blink
            6. Fade
            7. Skew
            8. Tint
          2. How it works...
          3. There's more...
        7. Controlling actions
          1. How to do it...
            1. Sequencing actions
            2. Spawning actions
            3. Repeating actions
            4. Reversing actions
            5. DelayTime
          2. How it works...
          3. There's more...
        8. Calling functions with actions
          1. How to do it...
          2. How it works...
          3. There's more...
        9. Easing actions
          1. How to do it...
          2. How it works...
        10. Using a texture atlas
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        11. Using a batch node
          1. How to do it...
          2. How it works...
          3. There's more...
        12. Using 3D modals
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        13. Detecting collisions
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        14. Drawing a shape
          1. How to do it...
            1. Drawing a dot
            2. Drawing lines
            3. Drawing circles
            4. Drawing a triangle
            5. Drawing rectangles
            6. Drawing a polygon
            7. Drawing a Bezier curve
          2. How it works...
      10. 3. Working with Labels
        1. Creating system font labels
          1. How to do it...
          2. How it works...
            1. Line break
            2. Text align
          3. There's more...
        2. Creating true type font labels
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        3. Creating bitmap font labels
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        4. Creating rich text
          1. How to do it...
            1. Drop shadow
            2. Outline
            3. Glow
          2. How it works...
          3. There's more...
      11. 4. Building Scenes and Layers
        1. Introduction
        2. Creating scenes
          1. How to do it...
          2. How it works...
        3. Transitioning between scenes
          1. How to do it...
          2. How it works...
        4. Transitioning scenes with effects
          1. How to do it...
          2. How it works...
          3. There's more...
        5. Making original transitions for replacing scenes
          1. How to do it...
          2. How it works...
          3. There's more...
        6. Making original transitions for popping scenes
          1. Getting ready
          2. How to do it...
          3. How it works...
        7. Creating layers
          1. How to do it...
          2. How it works...
        8. Creating modal layers
          1. How to do it...
          2. How it works...
      12. 5. Creating GUIs
        1. Introduction
        2. Creating menus
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        3. Creating buttons
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        4. Creating checkboxes
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        5. Creating loading bars
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        6. Creating sliders
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        7. Creating text fields
          1. How to do it...
          2. How it works...
          3. There's more...
        8. Creating scroll views
          1. How to do it...
          2. How it works...
        9. Creating page views
          1. How to do it...
          2. How it works...
        10. Creating list views
          1. How to do it...
          2. How it works...
      13. 6. Playing Sounds
        1. Playing background music
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        2. Playing a sound effect
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        3. Controlling volume, pitch, and balance
          1. How to do it...
          2. How it works...
        4. Pausing and resuming background music
          1. How to do it...
          2. How it works...
          3. There's more...
        5. Pausing and resuming sound effects
          1. How to do it...
          2. How it works...
          3. There's more...
        6. Playing background music and a sound effect by using AudioEngine
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        7. Playing movies
          1. Getting ready
          2. How to do it...
          3. How it works...
      14. 7. Working with Resource Files
        1. Selecting resource files
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        2. Managing resource files
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Using SQLite
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        4. Using .xml files
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Using .plist files
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        6. Using .json files
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
      15. 8. Working with Hardware
        1. Introduction
        2. Using native code
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
        3. Changing the processing using the platform
          1. How to do it...
          2. How it works...
          3. There's more…
        4. Using the acceleration sensor
          1. How to do it...
          2. How it works...
          3. There's more…
        5. Keeping the screen on
          1. How to do it...
          2. How it works...
        6. Getting dpi
          1. How to do it...
          2. How it works...
        7. Getting the maximum texture size
          1. How to do it...
          2. How it works...
          3. There's more…
      16. 9. Controlling Physics
        1. Introduction
        2. Using the physics engine
          1. How to do it...
          2. How it works...
          3. There's more…
        3. Detecting collisions
          1. How to do it...
          2. How it works...
        4. Using joints
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
        5. Changing gravity by using the acceleration sensor
          1. Getting ready
          2. How to do it...
          3. How it works...
      17. 10. Improving Games with Extra Features
        1. Introduction
        2. Using Texture Packer
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
        3. Using Tiled Map Editor
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
        4. Getting the property of the object in the tiled map
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Using Physics Editor
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Using Glyph Designer
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
      18. 11. Taking Advantages
        1. Introduction
        2. Using encrypted sprite sheets
          1. How to do it...
          2. How it works...
          3. There's more…
        3. Using encrypted zip files
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Using encrypted SQLite files
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
        5. Creating Observer Pattern
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
        6. Networking with HTTP
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
      19. Index