cocos2d-js 進度條(ccui擴展)

網上關於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"],

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章