在Cocos2D-X中使用新成员创建图层?

时间:2014-01-03 01:50:32

标签: c++ constructor cocos2d-x

在Cocos2D-X中,我创建了一个指向当前场景的指针来初始化GameObject管理器(试图抽象出一些Cocos2D API)。

我的标题如下:

class GameplayScene : public cocos2d::CCLayer
{

private:
    CCTMXTiledMap *_tileMap;
    CCTMXLayer *_background;
    CCSprite *_sprite;
    CCPoint _firstPoint;
    ObjectManager objectManager;

public:
    void feedback(CCObject * swipe);
    bool isBlocked(CCPoint point);



    // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
    virtual bool init();

    // there's no 'id' in cpp, so we recommend returning the class instance pointer
    static cocos2d::CCScene* scene();

    void update(float delta);

    CCPoint tileCoordForPosition(CCPoint position);
    CCPoint tileToPosition(CCPoint position);

    // a selector callback
    void menuCloseCallback(CCObject* pSender);

    // implement the "static node()" method manually
    CREATE_FUNC(GameplayScene);
};

然而,我很快被告知我正在调用“隐式删除默认构造函数”。任何人都可以向我解释这里发生了什么?

1 个答案:

答案 0 :(得分:1)

让GameplayScene构造函数像这样公开

class GameplayScene : public cocos2d::CCLayer
{
public:
    GameplayScene() {}

与“deleted default constructor headache”相同。