您的位置:首页 > 移动开发 > Cocos引擎

cocos2d-js 进度条(ccui扩展)

2015-11-13 23:11 513 查看
网上关于cocos2d-js的资料有点少,都是自己研究官方的样例。。。做个记录

进度条就很常用的一个ui

ccui扩展提供了一个比较方便的实现

只要设置相关参数就可以使用,跟Android的进度条差不多

代码:

this._loading = new ccui.LoadingBar();

this._loading.setName("LoadingBar");
this._loading.loadTexture(res.loading_1);//设置进度条的加载图片
this._loading.setPercent(30);//开始的进度
this._loading.x = screenSize.width / 2;
this._loading.y = screenSize.height / 2 + this._loading.height / 4;
this.addChild(this._loading);

this.scheduleUpdate();//自动更新


update: function (dt) {
this._count++;
if (this._count > 100) {
this._count = 0;
}

this._loading && this._loading.setPercent(this._count);
}


以上大部分是官方dome给出的代码。

值得提醒的是,要是使用ccui相关扩展需要在Porject.json文件中的modules中添加
extensions模块,不然会报错的哟!

"modules" : ["cocos2d","extensions"],
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: