顾名思义,这里缓存的是精灵框帧CCSpriteFrame,它主要服务于多张碎图合并出来的纹理图片。这种纹理在一张大图中包含了多张小图,直接通过CCTextureCache引用会有诸多不便,因而衍生出来精灵框帧的处理方式,即把截取好的纹理信息保存在一个精灵框帧内,精灵通过切换不同的框帧来显示出不同的图案。
CCSpriteFrameCache的常用接口和CCTextureCache类似,不再赘述了,唯一需要注意的是添加精灵帧的配套文件-- 一个plist文件和一张大的纹理图。下面列举了CCSpriteFrame Cache常用的方法:
/** Returns the shared instance of the Sprite Frame cache */
static CCSpriteFrameCache* sharedSpriteFrameCache(void);
/** Adds multiple Sprite Frames from a plist file.
* A texture will be loaded automatically. The texture name will composed by replacing the .plist suffix with .png
* If you want to use another texture, you should use the addSpriteFramesWithFile:texture method.
*/
void addSpriteFramesWithFile(const char *pszPlist);
/** Removes unused sprite frames.
* Sprite Frames that have a retain count of 1 will be deleted.
* It is convenient to call this method after when starting a new Scene.
*/
void removeUnusedSpriteFrames(void);