使用CCCallFuncN或其他东西调用方法

时间:2013-01-10 10:00:37

标签: c++ objective-c methods cocos2d-x

代码:

prog.h

public:

virtual bool init();  
static cocos2d::CCScene* scene();
CREATE_FUNC(ProgScene);
void spriteMoveFinished(CCNode* sender);

void endCallback(CCObject* pSender);
void endCallbackWork(CCNode* pSender);

prog.cpp

void ProgScene::spriteMoveFinished(CCNode* sender)
{
    CCMessageBox("Sprite Move Finished","Sprite Move Finished");
    this->runAction(CCCallFuncN::actionWithTarget( this, callfuncN_selector(ProgScene::endCallbackWork)));  // WORK
 // this->runAction(CCCallFuncN::actionWithTarget( this, callfuncN_selector(ProgScene::endCallback)));  // NOT WORK
}

void ProgScene::endCallback(CCObject* pSender)
{
    ...
    CCMessageBox("From endCallback","From endCallback");
}

void ProgScene::endCallbackWork(CCNode* sender)
{
    ...
    CCMessageBox("from endCallbackWork","from endCallbackWork");
}

我是cpp的初学者,请帮助我。

如何从方法actionWithTarget调用方法endCallback? 当我使用

this->runAction(CCCallFuncN::actionWithTarget( this, callfuncN_selector(ProgScene::endCallback)));

它返回:

error C2440: 'type cast' : cannot convert from 'void (__thiscall ProgScene::* )(cocos2d::CCObject *)' to 'cocos2d::SEL_CallFuncN'
1>        Pointers to members have different representations; cannot cast between them

endCallbackWork

合作得很好
this->runAction(CCCallFuncN::actionWithTarget( this, callfuncN_selector(ProgScene::endCallbackWork)));

也许我可以使用另一种方式而不是以下方式?

this->runAction(CCCallFuncN::actionWithTarget( this, callfuncN_selector(ProgScene::endCallback)));

0 个答案:

没有答案