Book Image

Cocos2d-x by Example: Beginner's Guide

By : Roger Engelbert
Book Image

Cocos2d-x by Example: Beginner's Guide

By: Roger Engelbert

Overview of this book

Table of Contents (19 chapters)
Cocos2d-x by Example Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – using debug draw in your Box2D project


Let's start by creating the project. In my machine, I created a game called MiniPool in my desktop. Here are the steps:

  1. Open Terminal and enter the following command:

    cocos new MiniPool -p com.rengelbert.MiniPool -l cpp -d /Users/rengelbert/Desktop/MiniPool
  2. Open the new project in Xcode.

  3. Now navigate to the Tests folder inside the Cocos2d-x framework folder. This can be found in tests/cpp-tests/Classes. Then open the Box2DTestBed folder.

  4. Drag the files GLES-Render.h and GLES-Render.cpp to your project in Xcode.

  5. You can also open the Box2dTest.cpp class in the test folder Box2DTest, as we're going to copy and paste a few of the methods from there.

  6. In the HelloWorldScene.h header file, leave the includes in place, but change the class declarations to match these:

    class HelloWorld : public cocos2d::Layer {
    public:
        virtual ~HelloWorld();
        HelloWorld();
        
       static cocos2d::Scene* scene();
        
        void initPhysics();
        void update...