AKever

导航

cocos2dx精灵帧的缓存 CCSpriteBatchNode CCSpriteFrameCache

cocos2dx精灵帧的缓存 CCSpriteBatchNode CCSpriteFrameCache 

//第一种方式直接创建,这样fps会很低大概30多,但是用的图片还是同一张
      for(int i = 0;i < 9000;i++)
{
CCSprite *sprite1 = CCSprite::create("helloworld.png");
sprite1->setPosition(ccp(CCRANDOM_0_1()*480,CCRANDOM_0_1()*320));

addchild(sprite1);

}
//第二种,通过CCBatchNode,同一个渲染方式。大概60多,多一倍,但是只能在同一个层渲染

CCSpriteBatchNode *pbtach = CCSpriteBatchNode::create("helloworld.png");
addchild(pbatch);
for(int i = 0;i < 9000;i++)
{
CCSprite *sprite2 = CCSprite::createWithTexture(pbtach->getTexture());
sprite2->setPosition(ccp(CCRANDOM_0_1()*480,CCRANDOM_0_1()*320));

addchild(sprite1);

} 
//第三种:比较好的方法,使用plist文件(plist就是把多张图片拼接成一张图片,通过xml,只是把图片的信息加载进来)
CCSpriteFrameCache *spriteCache = CCSpriteCache::SharedSpriteCahce();
spriteCache->addSpriteFrameWithFile("sprite.plist");
//加载plist文件
CCSpriteBatchNode *pbtach = CCSpriteBatchNode::create("sprite.png");//加载精灵表
for(int i = 0;i < 9;i++)
{
char str[50] = {0};//初始化为0
sprintf(str,"gross%d.png",i+1);
//都是用图片的路径,到时候通过plist文件查找到sprite.png里的信息
CCSprite *sprite2 = CCSprite::createWithSpriteFrameName(str);
//这里的文件是从sprite.png加载的
sprite2->setPosition(ccp(CCRANDOM_0_1()*480,CCRANDOM_0_1()*320));
addChild(sprite2);
} 
   3.cocos2dx动画缓存


   TexturePacker//图片拼接

 

posted on 2014-06-09 21:40  AKever  阅读(323)  评论(0)    收藏  举报