TangIDE開發技巧之自訂資源載入視窗進度條

來源:互聯網
上載者:User

標籤:tangide   cantk   tangram   html5遊戲開發   事件   

用TangIDE開發遊戲的朋友都知道,你可以像編輯普通的視窗一樣編輯資源載入視窗,加入各種豐富的控制項和動畫效果,但是進度條相對比較單調,現在進度條預設是兩張小圖,載入時按九宮格來繪製,如果你不想用九宮格,想用兩張水平長圖替代它們,那麼你可以在資源載入視窗的onSystemInit事件下,重寫進度條控制項(UIProgressBar)的drawBgImageH方法(這裡的H表示水平形狀的進度條),改變圖片的繪製方式。

var me = this;var win = this.getWindow();//顯示對象win.find("資源載入進度條").drawBgImageH = function(canvas) {    var image = null;    var h = this.h >> 1;    var y = (this.h - h)>> 1;    var r = this.roundRadius ? this.roundRadius : 0;    image = this.getHtmlImageByType(UIElement.IMAGE_DEFAULT);    if(image) {        canvas.drawImage(image, 0, 0, image.width, image.height, 0, 0, this.w, image.height);    }    else {        canvas.beginPath();        canvas.translate(0, y);        drawRoundRect(canvas, this.w, h, r);        canvas.translate(0, -y);        canvas.fillStyle = this.style.fillColor;        canvas.fill();    }    var fgImage = this.getHtmlImageByType(UIElement.IMAGE_NORMAL_FG);    if(image) {        y = Math.abs(fgImage.height - image.height) >> 1;        canvas.drawImage(fgImage, 0, 0, Math.round(fgImage.width * this.value), fgImage.height, 0, y, Math.round(this.w * this.value), fgImage.height);    }    else {        if(w > 2 * r) {            canvas.beginPath();            canvas.translate(0, y);            drawRoundRect(canvas, w, h, r);            canvas.fillStyle = this.style.lineColor;            canvas.fill();        }    }    return;}

對比原始的drawBgImageH方法可能看的更清楚

UIProgressBar.prototype.drawBgImageH = function(canvas) {    var image = null;    var h = this.h >> 1;    var y = (this.h - h)>> 1;    var r = this.roundRadius ? this.roundRadius : 0;    image = this.getHtmlImageByType(UIElement.IMAGE_DEFAULT);    if(image) {        drawNinePatchEx(canvas, image, 0, 0, image.width, image.height, 0, y, this.w, h);    }    else {        canvas.beginPath();        canvas.translate(0, y);        drawRoundRect(canvas, this.w, h, r);        canvas.translate(0, -y);        canvas.fillStyle = this.style.fillColor;        canvas.fill();    }    var w = Math.round(this.w * this.value);    image = this.getHtmlImageByType(UIElement.IMAGE_NORMAL_FG);    if(image) {        drawNinePatchEx(canvas, image, 0, 0, image.width, image.height, 0, y, w, h);    }    else {        if(w > 2 * r) {            canvas.beginPath();            canvas.translate(0, y);            drawRoundRect(canvas, w, h, r);            canvas.fillStyle = this.style.lineColor;            canvas.fill();        }    }    return;}

TangIDE開發技巧之自訂資源載入視窗進度條

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.