cocos2d-x 3.0 Loading界面实现(2)

来源:未知 责任编辑:责任编辑 发表时间:2015-01-01 13:14 点击:

void LoadingScene::loadingLogic(float dt){
	_curProgress ++;
	if(_curProgress > 100){
		//begin the game choose scene
		Director::getInstance()->replaceScene(TransitionFade::create(0.5f,ChooseScene::createScene()));
		return;
	}
	_progressBar->setValue(_curProgress);

	int startX = _progressBar->getPositionX() - _progressBar->getContentSize().width / 2 +10 ;
	int unitX = _progressBar->getContentSize().width / 100;

	_barTip->setPositionX(startX + _curProgress * unitX);
	char str[10] = {0};
	sprintf(str,"%d%",_curProgress);

	_barTipLabel->setString(str);

}

咦,看到这里有没有觉得哪里不对?好吧,被你发现了,说好的资源加载哪里去了?而且资源加载的进度百分比怎么算的呢?


好吧,继续,比如我们有一百张图片资源。。。(为什么不是99张?)


void LoadingScene::onEnter(){
	Layer::onEnter();
	//加载一次图片资源就回调一次
	Director::getInstance()->getTextureCache()->addImageAsync("1.png",this,callfunc_selector(LoadingScene::loadingCallback));
	...
	...
	...
	Director::getInstance()->getTextureCache()->addImageAsync("100.png",this,callfunc_selector(LoadingScene::loadingCallback));
	
}

然后回调函数实现,每次执行动态更新提示框的位置和文字标签的信息,到了第一百次,就开启另外一个界面,恩,还是这么简单。。。


void LoadingScene::loadingCallback(){
	_curProgress ++;
	if(_curProgress > 100){
		//begin the game choose scene
		Director::getInstance()->replaceScene(TransitionFade::create(0.5f,ChooseScene::createScene()));
		return;
	}
	_progressBar->setValue(_curProgress);

	int startX = _progressBar->getPositionX() - _progressBar->getContentSize().width / 2 +10 ;
	int unitX = _progressBar->getContentSize().width / 100;

	_barTip->setPositionX(startX + _curProgress * unitX);
	char str[10] = {0};
	sprintf(str,"%d%",_curProgress);

	_barTipLabel->setString(str);

}

其实思路都差不多啦,大概就是根据( 已经加载的图片数 / 总图片资源数)百分比来算出进度条的百分比来滑动,或者干脆把进度条最大值设置成图片资源总数,加载多少就滑动多少。。


==================================


恩,就这样子吧,好困的夜晚。。晚安


发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • cocos2d-x学习笔记(19)--label 、label atlas
  • cocos2d-x学习笔记(23)--地图的使用3--CCTMXLayer
  • Cocos2d-x学习(一):HelloWorld
  • cocos2dx在xcode下开发,编译到android上(2)
  • cocos2d 设置屏幕默认方向
  • cocos2d-x学习笔记(22)--地图的使用2(TMX) --Z-Order、AnchorPoi
  • Cocos2d-x 2.0 之 Actions “三板斧” 之一
  • cocos2d-x学习笔记(18)--游戏打包(windows平台)
  • cocos2d-x学习笔记(16)--spritesheet(精灵表单)
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1