mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-06 19:42:39 +08:00
Merge pull request #1717 from zilongshanren/improve-progress-bar
Improve progress bar
This commit is contained in:
@@ -154,25 +154,34 @@ var ProgressBar = cc.Class({
|
||||
totalWidth = entitySize.width;
|
||||
totalHeight = this.totalLength;
|
||||
break;
|
||||
case Mode.FILLED:
|
||||
}
|
||||
|
||||
//handling filled mode
|
||||
if (this.mode === Mode.FILLED) {
|
||||
if (this.barSprite.type !== cc.Sprite.Type.FILLED) {
|
||||
cc.warn('ProgressBar FILLED mode only works when barSprite\'s Type is FILLED!');
|
||||
} else {
|
||||
if (this.reverse) {
|
||||
actualLenth = actualLenth * -1;
|
||||
}
|
||||
this.barSprite.fillRange = actualLenth;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (this.barSprite.type !== cc.Sprite.Type.FILLED) {
|
||||
|
||||
var anchorOffsetX = anchorPoint.x - entityAnchorPoint.x;
|
||||
var anchorOffsetY = anchorPoint.y - entityAnchorPoint.y;
|
||||
var finalPosition = cc.p(totalWidth * anchorOffsetX, totalHeight * anchorOffsetY);
|
||||
|
||||
entity.setPosition(cc.pAdd(entityPosition, finalPosition));
|
||||
|
||||
entity.setAnchorPoint(anchorPoint);
|
||||
entity.setContentSize(finalContentSize);
|
||||
} else {
|
||||
cc.warn('ProgressBar non-FILLED mode only works when barSprite\'s Type is non-FILLED!');
|
||||
}
|
||||
}
|
||||
|
||||
if (this.barSprite.type !== cc.Sprite.Type.FILLED) {
|
||||
|
||||
var anchorOffsetX = anchorPoint.x - entityAnchorPoint.x;
|
||||
var anchorOffsetY = anchorPoint.y - entityAnchorPoint.y;
|
||||
var finalPosition = cc.p(totalWidth * anchorOffsetX, totalHeight * anchorOffsetY);
|
||||
|
||||
entity.setPosition(cc.pAdd(entityPosition, finalPosition));
|
||||
|
||||
entity.setAnchorPoint(anchorPoint);
|
||||
entity.setContentSize(finalContentSize);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -221,16 +230,23 @@ var ProgressBar = cc.Class({
|
||||
animatable: false
|
||||
},
|
||||
|
||||
_N$totalLength: 1,
|
||||
/**
|
||||
* !#en The total width or height of the bar sprite.
|
||||
* !#zh 进度条实际的总长度
|
||||
* @property {Number} totalLength
|
||||
*/
|
||||
totalLength: {
|
||||
default: 1,
|
||||
range: [0, Number.MAX_VALUE],
|
||||
tooltip: CC_DEV && 'i18n:COMPONENT.progress.total_length',
|
||||
notify: function(value) {
|
||||
get: function () {
|
||||
return this._N$totalLength;
|
||||
},
|
||||
set: function(value) {
|
||||
if (this.mode === Mode.FILLED) {
|
||||
value = cc.clamp01(value);
|
||||
}
|
||||
this._N$totalLength = value;
|
||||
this._updateBarStatus();
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user