在我的游戏中,我有一个"火箭"键入,我想在其上运行一系列操作。首先,它必须运行爆炸动画,然后从游戏中移除自己。为此我使用了以下代码,但它不起作用并导致运行时错误。
火箭课程:
void Rocket::movingRocket(float dt)
{
// some codes ...
if(rocketIsCollideWithEnemy()) // run only one time
{
this->stopAllActions();
CCAnimation *animation = CCAnimation::create();
for (int i = 0; i < EXPLOSION_FRAME_NUMBER; i++)
{
CCString *str = CCString::createWithFormat("/explosion-%d.png", i);
animation->addSpriteFrameWithFileName(str->getCString());
}
animation->setDelayPerUnit(0.06f);
CCAnimate *animate = CCAnimate::create(animation);
CCCallFuncN* remove_rocket = CCCallFuncN::create(this, callfuncN_selector(Rocket::removeRocket));
this->runAction(CCSequence::create(animate,remove_rocket, NULL));
this->unschedule(schedule_selector(Rocket::movingRocket));
}
}
为了移除我使用的火箭:
void Rocket::removeRocket(CCObject *pSender)
{
((CCNode*)pSender)->removeFromParentAndCleanup(true);
}
当我运行上述代码时,以下代码中出现错误,部分为Cocos2d,第4行:
void CCAnimate::update(float t)
{
// some codes...
if( splitTime <= t )
{
CCAnimationFrame* frame = (CCAnimationFrame*)frames->objectAtIndex(i);
frameToDisplay = frame->getSpriteFrame();
((CCSprite*)m_pTarget)->setDisplayFrame(frameToDisplay);
CCDictionary* dict = frame->getUserInfo();
if( dict )
{
//TODO: [[NSNotificationCenter defaultCenter] postNotificationName:CCAnimationFrameDisplayedNotification object:target_ userInfo:dict];
}
m_nNextFrame = i+1;
}
// some codes...
}
什么可能导致我的问题?