TangIDE开发技巧之自定义资源加载窗口进度条

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(fgImage && 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 {
        var w = Math.round(this.w * this.value);
        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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值