//将合成图片中的某一桢图片大批量的添加到场景中,进行场景的优化
//方法一:
//将合成的图片的plist添加到缓存
/*CCSpriteFrameCache* frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
frameCache->addSpriteFramesWithFile("jiji.plist");
//获取其中的一个图片给CCSpriteFrame
CCSpriteFrame*frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("alien.png");
//将frame的Texture赋给CCSpriteBatchNode
CCSpriteBatchNode*batchNode = CCSpriteBatchNode::createWithTexture(frame->getTexture(),100);
batchNode->setPosition(CCPointZero);
this->addChild(batchNode);
for (int i=0;i<1000;i++ )
{
CCSprite *testIcon = CCSprite::createWithSpriteFrameName("alien.png");
testIcon->setPosition(ccp(size.x/2,size.y/2 + 60));
batchNode->addChild(testIcon);
}*/
//方法二:
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("jiji.plist");
CCSpriteBatchNode*batchNode = CCSpriteBatchNode::create("jiji.pvr.ccz");
batchNode->setPosition(CCPointZero);
this->addChild(batchNode);
for (int i=0;i<10000;i++ )
{
CCSprite *testIcon = CCSprite::createWithSpriteFrameName("alien.png");
testIcon->setPosition(ccp(size.x/2,size.y/2 + 60));
batchNode->addChild(testIcon);
}
[cocos2d-x]将合成的图片中的某一个图大批量的加载到图层中
最新推荐文章于 2025-05-07 18:43:26 发布
本文介绍两种使用Cocos2d-x引擎批量添加图片至场景的方法,以实现场景优化。第一种方法通过添加plist文件到缓存,并利用CCSpriteFrame设置纹理;第二种方法直接创建批处理节点并加载特定格式的资源文件。
4150

被折叠的 条评论
为什么被折叠?



