我智商爆棚
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

47 lines
1.2 KiB

//遮罩实现的进度条,cocos自带的进度条是九宫格缩放的
const {ccclass, property, menu} = cc._decorator;
@ccclass
@menu("UI/MaskProgress")
export default class MaskProgress extends cc.Component {
@property(cc.Node)
iconFolowed: cc.Node = null;
@property(cc.Label)
labelProgress: cc.Label = null;
public get progress()
{
return this._progress;
}
public set progress(value: number)
{
if (this.flag)
{
if (value < 1) this.flag = false;
return;
}
if (value > 1) { value = 1; this.flag = true; }
this._progress = value;
if (this.maskNode)
{
this.maskNode.width = Math.floor(value * this.node.width);
if (this.iconFolowed) this.iconFolowed.x = this.maskNode.x + this.maskNode.width;
if (this.labelProgress) this.labelProgress.string = Math.floor(value * 100) + "%";
}
}
private _progress: number;
private maskNode: cc.Node;
private flag: boolean = false;
onLoad()
{
this.maskNode = this.node.children[0];
this.progress = 0;
if (this.labelProgress) this.labelProgress.string = "0%";
}
}