指向成员的指针有不同的表示形式;不能在他们之间施放cocos2d-x

时间:2015-10-12 05:13:55

标签: cocos2d-x

x和编程的新手,我正在制作一个反转,但某种方式它给我一个错误。 有谁可以帮助我?

CCSprite* bg = CCSprite::create("Images/Reversi.png");
addChild(bg, 1);
bg->setAnchorPoint(CCPointZero);

_midArea = CCLayerColor::create(ccc4(255, 0, 0, 0), 600, 600);
addChild(_midArea, 2);
_midArea->setAnchorPoint(CCPointZero);
_midArea->setPosition(ccp(88, 271));

CCMenu* menu = CCMenu::create();
_midArea->addChild(menu, 10);
menu->setAnchorPoint(ccp(0, 0));
menu->setPosition(ccp(0, 0));

_gameOver = CCMenuItem::create();
_gameOver->setTarget(this, menu_selector(GameLayer::startNewGame));
menu->addChild(_gameOver);
_gameOver->setAnchorPoint(ccp(0.5, 0.5));
_gameOver->setPosition(ccp(300, 300));
_gameOver->setContentSize(getContentSize());
CCSprite* overImg = CCSprite::create("Images/GameOver.png");
_gameOver->addChild(overImg);
CCSize layerSize = getContentSize();
overImg->setPosition(ccp(layerSize.width / 2, layerSize.height / 2));
_gameOver->setVisible(false);
_gameOver->setEnabled(false);

float gridSize = 75;

CCTextureCache* textureCache = CCTextureCache::sharedTextureCache();

_whiteTex = textureCache->addImage("Images/ReversiWhitePiece.png");
_blackTex = textureCache->addImage("Images/ReversiBlackPiece.png");
_whiteTex->retain();
_blackTex->retain();

for (int i = 0; i < NUM_ROW; i++) {
    for (int j = 0; j < NUM_COL; j++) {
        CCMenuItem* item = CCMenuItem::create();
        item->setContentSize(CCSizeMake(gridSize, gridSize));
        menu->addChild(item);
        item->setTarget(this, menu_selector(GameLayer::onClickGrid));
        item->setTag(i * NUM_COL + j);
        item->setAnchorPoint(ccp(0, 0));
        item->setPosition(ccp(j * gridSize, i * gridSize));

        _gridSprites[i][j] = CCSprite::createWithTexture(_whiteTex);
        _midArea->addChild(_gridSprites[i][j], 2);
        _gridSprites[i][j]->setVisible(false);
        _gridSprites[i][j]->setAnchorPoint(item->getAnchorPoint());
        _gridSprites[i][j]->setPosition(item->getPosition());

        _grids[i][j] = FLAG_NONE;

        if ((i == 3 && j == 3) || (i == 4 && j == 4)) {
            _grids[i][j] = FLAG_BLACK;
            _blackCount++;
            _gridSprites[i][j]->setTexture(_blackTex);
            _gridSprites[i][j]->setVisible(true);
        }
        else if ((i == 3 && j == 4) || (i == 4 && j == 3)) {
            _grids[i][j] = FLAG_WHITE;
            _whiteCount++;
            _gridSprites[i][j]->setTexture(_whiteTex);
            _gridSprites[i][j]->setVisible(true);
        }
    }
}

_curFlag = FLAG_BLACK;
_curFlagSprite = CCSprite::createWithTexture(_blackTex);
_midArea->addChild(_curFlagSprite, 1);
_curFlagSprite->setAnchorPoint(ccp(0, 0));
_curFlagSprite->setPosition(ccp(7 * 75, 75 * 8 + 25));

setKeypadEnabled(true);

scheduleUpdate();

printf("GameLayer::init whiteCount %d, blackCount %d\n", _whiteCount,
    _blackCount);

return true;

这是一个错误

1>e:\games\game maker\cocos2d-x-2.2.6\cocos2d-x-2.2.6\projects\reversi2\classes\gamescene.cpp(48): error C2440: 'type cast' : cannot convert from 'void (__thiscall GameLayer::* )(cocos2d::CCNode *)' to 'cocos2d::SEL_MenuHandler'Pointers to members have different representations; cannot cast between them

然后它也给我这个

1>e:\games\game maker\cocos2d-x-2.2.6\cocos2d-x-2.2.6\projects\reversi2\classes\gamescene.cpp(48): error C2660: 'cocos2d::CCMenuItem::setTarget' : function does not take 1 arguments

抱歉英语不是我母亲的语言,所以希望大家都明白:v

1 个答案:

答案 0 :(得分:0)

我不记得解决方案,我认为这是关于一个类型转换:)