0

当我运行下面的动画代码时,它会在模拟器上崩溃。但在设备上工作正常。

代码:-

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))));

正是在 ccsequence 上它崩溃了。我用 Exc_Bad_access 得到了这个“引用计数应该大于 0”在此处输入图像描述

4

1 回答 1

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));

更多信息在这里

于 2014-06-23T09:05:36.170 回答