分类: C/C++
2015-03-16 14:23:52
CCSpriteFrameCache 是一个单例模式的实现的 ,全局的 SpriteFrame 缓冲区。
可以用来管理游戏中所有的 SpriteFrame.
CCSpriteFrameCache 可以通过加载 xml 文件来创建动作帧。。
--------------------------------------------------------------------------------------------
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("animations/grossini.plist");
CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
m_pSprite2 = CCSprite::spriteWithSpriteFrameName("grossini_dance_01.png");
CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
cache->addSpriteFramesWithFile("animations/grossini-aliases.plist", "animations/grossini-aliases.png");
CCAnimationCache::sharedAnimationCache()->addAnimation(animation, "dance");
char str[100] = {0};
for(int i = 1; i < 15; i++)
{
sprintf(str, "grossini_dance_%02d.png", i);
CCSpriteFrame* frame = cache->spriteFrameByName( str );
animFrames->addObject(frame);
}
char str[100] = {0};
for(int i = 1; i < 15; i++)
{
sprintf(str, "grossini_dance_%02d.png", i);
CCSpriteFrame* frame = cache->spriteFrameByName( str );
animFrames->addObject(frame);
}
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("animations/grossini.plist");
CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
cache->removeSpriteFramesFromFile("animations/grossini_gray.plist");
m_pSprite2 = CCSprite::spriteWithSpriteFrameName("grossini_dance_01.png");
CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
cache->addSpriteFramesWithFile("animations/grossini-aliases.plist", "animations/grossini-aliases.png");
CCAnimationCache::sharedAnimationCache()->addAnimation(animation, "dance");
------------------------------------------------------------------------------------------
CCMutableArray
char str[100] = {0};
for(int i = 1; i < 15; i++)
{
sprintf(str, "grossini_dance_%02d.png", i);
CCSpriteFrame* frame = cache->spriteFrameByName( str );
animFrames->addObject(frame);
}
CCAnimation* animation = CCAnimation::animationWithFrames(animFrames);
m_pSprite1->runAction( CCRepeatForever::actionWithAction( CCAnimate::actionWithAnimation(animation, false) ) );