{
//初始化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); } 原文链接:https://www.f2er.com/cocos2dx/346891.html