android和ios开发进度条,cocos2d-x  android&ios开发 简单实现异步加载图片缓存loading进度条...

CCTextureCache::sharedTextureCache()->addImageAsync(char*

fileName,CCObject*

target,SEL_CallfuncO

selector);

此方法将图片文件加载进缓存,并且在加载完成后调用一个回调函数。

首先先创建一个进度条loadingImage:

CCSize size =

CCDirector::sharedDirector()->getWinSize();

CCSprite* temp =

CCSprite::create("xxx.png");

temp->setAnchorPoint(ccp(0,0));

CCProgressTimer*loadingImage

= CCProgressTimer::create(temp);

this->addChild(loadingImage);

loadingImage->setPosition(ccp(size.width/2,

size.height/2));

loadingImage->setType(kCCProgressTimerTypeBar);//设置进度条类型,选用bar类型

loadingImage->setMidpoint(ccp(0,0.5));//设置进度条起始点,范围是(0,0)~(1,1)

loadingImage->setBarChangeRate(ccp(1,0))//设置进度条的变化速率

loadingImage->setTag(100);

loadingImage->retain();

第二步需要创建我们控制loading进度条的回调方法

void Loading::callBackEvent(CCObject*

object)

{

static int progressCount =

0;//设置一个静态计数器,记录使用回调方法的次数

CCProgressTimer* loadingImage

= (CCProgressTimer

*)this->getChildByTag(100);

loadingImage->stopAllActions();

progressCount++;//计数加1

CCProgressTo* to =

CCProgressTo::create(0.2f,100 / i * progressCount);//参数i为一个int类型的变量,他表示需要加载的图片数。

loadingImage->runAction(to);//运行进度条动画

if (i == progressCount)//当回调方法的调用次数达到最后一次时,将场景加载进来

{

CCDirector::shareDirector()->replaceScene(nextScene);

}

}

最后我们只需要依次调用addImageAsync这个方法就行了

CCTextureCache::sharedTextureCache()->addImageAsync("xxx_1.png",this,callfuncO_selector(Loading::callBackEvent));

CCTextureCache::sharedTextureCache()->addImageAsync("xxx_1.png",this,callfuncO_selector(Loading::callBackEvent));

CCTextureCache::sharedTextureCache()->addImageAsync("xxx_1.png",this,callfuncO_selector(Loading::callBackEvent));CCTextureCache::sharedTextureCache()->addImageAsync("xxx_1.png",this,callfuncO_selector(Loading::callBackEvent));

CCTextureCache::sharedTextureCache()->addImageAsync("xxx_1.png",this,callfuncO_selector(Loading::callBackEvent));

CCTextureCache::sharedTextureCache()->addImageAsync("xxx_1.png",this,callfuncO_selector(Loading::callBackEvent));

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值