在 Cocos2D-X 中创建具有新成员的图层

Creating layers with new members in Cocos2D-X?

本文关键字:新成员 图层 Cocos2D-X 创建      更新时间:2023-10-16

在 Cocos2D-X 中,我创建了一个指向当前场景的指针来初始化游戏对象管理器(试图抽象出一些 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);
};

但是,我立即被告知我正在调用"隐式删除的默认构造函数"。谁能向我解释一下这里发生了什么?

像这样公开GameplayScene构造函数

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

与"删除默认构造函数头痛"相同。