/* 加载图片资源到SpriteFrame缓存池*/
CCSpriteFrameCache *cache=CCSpriteFrameCache::sharedSpriteFrameCache();
cache->addSpriteFramesWithFile("ghosts.plist", "ghosts.png");
/* 创建CCTexture2D对象*/
CCTexture2D *texturee=CCTextureCache::sharedTextureCache()->textureForKey("ghosts.png");
/* 使用CCTexture2D对象创建BatchNode */
CCSpriteBatchNode *batchnode=CCSpriteBatchNode::createWithTexture(texturee, 10);
/* 添加BatchNode到场景*/
this->addChild(batchnode,1);
/* 批量创建精灵,并把精灵加入batchnode */
batchnode->setPosition(ccp(size.width/3,size.height/3));
for (int i=0; i<10; i++) {
int x=CCRANDOM_0_1()*320;
int y=CCRANDOM_0_1()*32;
CCSprite *spritte=CCSprite::createWithSpriteFrameName("father.gif");
spritte->setPosition(ccp(x,y));
batchnode->addChild(spritte);
}
//从缓存总读取图片,图片是在ghosts.png中集成的
CCMenuItemImage *closed=CCMenuItemImage::create();
closed->setNormalSpriteFrame(cache->spriteFrameByName("sister1.gif"));
closed->setSelectedSpriteFrame(cache->spriteFrameByName("sister2.gif"));
closed->initWithTarget(this, menu_selector(HelloWorld::menuCloseCallback));
closed->setPosition(ccp(size.width/5,size.height/5));
//this->addChild(closed);
CCMenu *menus=CCMenu::create(closed,NULL);
this->addChild(menus);