我試圖將動畫從cocos2d
轉換爲cocos2d-x
,但無濟於事。我沒有收到任何明顯的錯誤消息,只是它發生在倒數第二行。Cocos2d-x動畫錯誤
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("swim_male.plist");
CCSpriteBatchNode *sceneSpriteBatchNode = CCSpriteBatchNode::batchNodeWithFile("swim_male.png");
this->addChild(sceneSpriteBatchNode);
CCAnimation* animation = CCAnimation::animation();
animation->setDelayPerUnit(.05f);
char* fn = new char;
for (int i = 1; i <= 10; i++) {
sprintf(fn, "character_Male00%02d.png", i);
CCSpriteFrame* pFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(fn);
animation->addSpriteFrame(pFrame);
}
CCSprite *spriteAnim = CCSprite::spriteWithSpriteFrameName("character_Male0001.png");
spriteAnim->setPosition(ccp(100, 200));
CCAnimate *animate = CCAnimate::actionWithAnimation(animation);
CCAction *act = CCRepeatForever::actionWithAction(animate);
spriteAnim->runAction(act);
sceneSpriteBatchNode->addChild(spriteAnim, 2);
什麼錯誤消息的文本? – Morion
EXEC_BAD_ACCESS – user1235155
這意味着其中一個變量是NULL。檢查調試器,什麼變量是NULL並導致崩潰 – Morion