//将合成图片中的某一桢图片大批量的添加到场景中,进行场景的优化
//方法一:
//将合成的图片的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]将合成的图片中的某一个图大批量的加载到图层中
最新推荐文章于 2021-01-29 23:21:39 发布