標籤: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開發技巧之自訂資源載入視窗進度條