Cocos2d-X 学习笔记 11 制作Loading视图

前端之家收集整理的这篇文章主要介绍了Cocos2d-X 学习笔记 11 制作Loading视图前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
void MyScene::menuChangeCallback(CCObject* pSender)

{

//初始化Loading界面

CCMenu *menu=(CCMenu *)getChildByTag(1); menu->setVisible(false); CCSize size=CCDirector::sharedDirector()->getWinSize(); labelLoading=CCLabelTTF::create("loading...","Arial",20); labelPercent=CCLabelTTF::create("0%",20); labelLoading->setPosition(ccp(size.width/2,size.height/2)); labelPercent->setPosition(ccp(size.width/2,size.height*0.3)); this->addChild(labelLoading); this->addChild(labelPercent); numberofSprites=200; numberofLoadedSprites=0; CCSprite *loadBg=CCSprite::create("sliderTrack.png"); loadBg->setPosition(ccp(size.width/2,size.height*0.2)); this->addChild(loadBg); loadProgress=CCProgressTimer::create(CCSprite::create("sliderProgress.png")); loadProgress->setBarChangeRate(ccp(1,0)); loadProgress->setType(kCCProgressTimerTypeBar); loadProgress->setMidpoint(ccp(0,0)); loadProgress->setPosition(ccp(size.width/2,size.height*0.2)); this->addChild(loadProgress,1); for(int i=0;i<100;i++) { CCTextureCache::sharedTextureCache()->addImageAsync("HelloWorld.png",this,callfuncO_selector(MyScene::loadingCallBack)); CCTextureCache::sharedTextureCache()->addImageAsync("icon.png",callfuncO_selector(MyScene::loadingCallBack)); } } //更新界面 void MyScene::loadingCallBack(CCObject* pSender) { numberofLoadedSprites++; char tmp[10]; float value=((float)numberofLoadedSprites/numberofSprites)*100; sprintf(tmp,"%d%%",(int)(value)); labelPercent->setString(tmp); loadProgress->setPercentage(value); if(numberofLoadedSprites==numberofSprites) { turnToScene(); } } //加载完成后需要做的事 void MyScene::turnToScene() { CCScene *sence=HelloWorld::scene(); CCDirector::sharedDirector()->replaceScene(sence); }

猜你在找的Cocos2d-x相关文章