我在做一个Loading界面的时候,用一个数组const char * str = {"Loading","Loading.","Loading..","Loading..."}
bool Load::init()
{
if(!CCLayer::init())
{
return false;
}
//这个方法用来每个一秒调用一次修改Loading,实现动态的一个效果
schedule(schedule_selector(Load::changeStr), 1.0f);
//这个scheduleUpdate是场景切换的方法
scheduleUpdate();
//scheduleOnce(schedule_selector(Load::update), 0);
return true;
}
int n=0;
void Load::changeStr()
{
this->unschedule(schedule_selector(Load::changeStr));
char * str[4]= {"Loading","Loading.","Loading..","Loading..."};
CCLabelTTF *label = CCLabelTTF::create(str[n], "Arial", 40);
label->setPosition(CCPointMake(160, 240));
this->addChild(label,0,1);
n=(++n)%4;
CCLog("%d",n);
schedule(schedule_selector(Load::del), 1.0f);
CCDirector::sharedDirector()->replaceScene(HelloWorld::scene());
}
void Load::del()
{
this->removeChildByTag(1);
}
void Load::update(float delta)
{
CCDirector::sharedDirector()->replaceScene(HelloWorld::scene());
}
我想实现一个动态显示Loading。。。
但是如果两个scheduleb不能同时运行,我的理解是主线程要么只能bu不断的执行刷新Loading。。。,要么就只能不断的监听update场景切换效果,不能同时执行。
我猜测的解决办法,将其中一个schedule放在多线程中去执行可以吗?
还是你有其他办法实现这个常见的loading动态加载效果,tell me!