我正在做一个cocos2d-x项目,结果被卡住了。我想调用一个函数,延迟,然后再次调用相同的函数。我使用的是cocos2d-x 2.2.5。以及针对Android的开发。
这就是我到目前为止得到的:
CCArray *arr = CCArray::create();
arr->addObject(pSprite);
arr->addObject(pGetal);
CCFiniteTimeAction *fun1 = CCCallFuncO::create(this, callfuncO_selector(GameLayer::animateFlip), arr);
CCDelayTime *delay = CCDelayTime::create(1.0);
pSprite->runAction(CCSequence::create(fun1, delay, fun1, NULL));我想调用的方法:
void GameLayer::animateFlip(CCObject *pSObj, CCObject *pGObj){
CCSprite *pSprite = (CCSprite *) pSObj;
CCLabelTTF *pGetal = (CCLabelTTF *) pSObj;
...
...
}该函数在同一个类中,需要两个参数。我尝试将两个参数(CCSprite和CCLabelTTF)都放入一个数组中,但在运行时崩溃...当我像这样调用函数时,没有发生错误:
this->animateFlip(sprite1, getal1);有谁知道吗?
发布于 2014-08-01 04:32:33
感谢你的回答,我已经按照Joachim的建议为我的按钮创建了一个结构,里面有sprite和标签。所有的按钮都放在一个数组中。我还向其中添加了函数animateFlip和showFlip。AnimateFlip运行良好,我可以从每个独立按钮的gamelayer中调用函数。
void GameLayer::ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent)
{
CCTouch *touch = (CCTouch *)pTouches->anyObject();
CCPoint location = touch->getLocationInView();
location = CCDirector::sharedDirector()->convertToGL(location);
for(int i = 0; i < 12; i++){
if(butArr[i].sprite->boundingBox().containsPoint(location)){
butArr[i].animateFlip();
break;
}
}
}结构:
struct Button
{
cocos2d::CCSprite *sprite;
cocos2d::CCLabelTTF *getal;
int getalINT;
void showFlip();
void animateFlip();
};但正如编程中的第一条规则告诉我们的那样,只要解决了一个问题,就会出现两个问题,我偶然发现了一个新问题:
void Button::showFlip()
{
CCFiniteTimeAction *fun1 = CCCallFunc::create(this, callfunc_selector(Button::animateFlip));
CCFiniteTimeAction *fun1 = CCCallFunc::create(this, callfunc_selector(Button::animateFlip));
CCDelayTime *delay = CCDelayTime::create(1.0f);
this->runAction(CCSequence::create(fun1, delay, fun2, NULL));
}CCCallFunc::create()请求一个上下文(我猜?),通常是'this',但在我的struct中'this‘指向Button。我怎样才能得到玩家的上下文?
再次感谢!
https://stackoverflow.com/questions/25058901
复制相似问题