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 – adding GameSprite.cpp


From here on, we'll create any new classes inside Xcode, but you could do it just as easily in Eclipse if you remember to update the Make file. I'll show you how to do that later in this chapter.

  1. In Xcode, select the Classes folder and then go to File | New | File and navigate to iOS | Source select C++ File.

  2. Call it GameSprite and make sure the Also create a header file option is selected.

  3. Select the new GameSprite.h interface file and replace the code there with this:

    #ifndef __GAMESPRITE_H__
    #define __GAMESPRITE_H__
    #include "cocos2d.h"
    using namespace cocos2d;
    class GameSprite : public Sprite {
    public:
       CC_SYNTHESIZE(Vec2, _nextPosition, NextPosition);
       CC_SYNTHESIZE(Vec2, _vector, Vector);
       CC_SYNTHESIZE(Touch*, _touch, Touch);
       GameSprite();
       virtual ~GameSprite();
       static GameSprite* gameSpriteWithFile(const char*  pszFileName);
       virtual void setPosition(const Vec2& pos) override;
       float radius();
    };
    #endif // __GAMESPRITE_H__...