2013-07-18 32 views
0

我有9个不同场景的34个.png图像文件。每当用户挑选的那些9个方案1,并根据该予使用生成动画以下使用.png文件的动画cocos2dx

std::string name; 
MixingScreen::animation = CCAnimation::create(); 
// load image file from local file system to CCSpriteFrame, then add into CCAnimation 
for (int i = 0; i < 34; i++) 
{ 
    std::stringstream st,ii; 
    st << Constants::flav; 
    if (i<10) 
    { 
     ii<<i; 
     name="screen/screen02/fx/sugar/0" + st.str()+"/a_0000"+ii.str()+".png"; 
    } 
    else 
    { 
     ii<<i; 
     name="screen/screen02/fx/sugar/0" + st.str()+"/a_000"+ii.str()+".png"; 
    } 
     //sprintf(szImageFileName, "Images/grossini_dance_%02d.png", i); 
    MixingScreen::animation->addSpriteFrameWithFileName(name.c_str()); 
    } 
    MixingScreen::animation->setDelayPerUnit(5.0f/34.0f); 

    action = CCAnimate::create(MixingScreen::animation); 
    CCCallFunc *done = CCCallFunc::create(this, callfunc_selector(MixingScreen::doneMixing)); 
    CCSequence *readySequence = CCSequence::create(action,done,NULL); 
    particles->runAction(readySequence); 

我面临的问题是,当该动画运行,有一个时间滞后(一切都停止几秒)然后开始动画。任何解决方案

回答

2

每次调用animation-> addSpriteFrameWithFileName()时,都会创建一个新的“CCSpriteFrame”。

相反,你应该先精灵帧添加到CCSpriteFrameCache和使用

animation->addSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameWithName("")) 

PS:这些函数的名称可能会有点不同,但我希望你明白我的意思。

+1

'CCSpriteFrameCache :: sharedSpriteFrameCache()'现在已被弃用。改为使用'CCSpriteFrameCache :: getInstance()'。 – namezero