当我运行以下动画代码时,它会在模拟器上崩溃。但在设备上工作正常。
代码: -
CCSprite* pSprite = CCSprite::create("pic2.png");
pSprite->setPosition( ccp(size.width/2, size.height/2) );
this->addChild(pSprite, 0);
//Animation
CCAnimation *animate = CCAnimation::create();
for (int i = 2; i <=7; i++)
{
char frameName[128] = {0};
sprintf(frameName, "pic%d.png", i);
animate->addSpriteFrameWithFileName(frameName) ;
}
animate->setDelayPerUnit(0.1f); // This animation contains 3 frames, will continuous 2.8 seconds.
animate->setRestoreOriginalFrame(true); // Return to the 1st frame after the 3rd frame is played.
CCAnimate *animaction = CCAnimate::create(animate);
pSprite->runAction(CCSequence::create(CCRepeat::create(animaction, 1),
CCDelayTime::create(2.0f),
CCCallFuncN::create(this, callfuncN_selector(HelloWorld::menuCloseCallback))));
正好在它的崩溃中崩溃。我得到了这个&#34;引用计数应该大于0&#34;使用Exc_Bad_acess
答案 0 :(得分:0)
尝试替换此行 -
pSprite->runAction(CCSequence::create(CCRepeat::create(animaction, 1),
CCDelayTime::create(2.0f),
CCCallFuncN::create(this, callfuncN_selector(HelloWorld::menuCloseCallback))));
带
pSprite->runAction(CCSequence::create(CCRepeat::create(animaction, 1),
CCDelayTime::create(2.0f),
CCCallFuncN::create(this, callfuncN_selector(HelloWorld::menuCloseCallback)),NULL));
更多信息here