Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
rexrainbow committed Oct 16, 2023
1 parent 3b3c55c commit 55f5d7b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
4 changes: 4 additions & 0 deletions examples/circularprogresscanvas/circularprogress.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class Demo extends Phaser.Scene {
barColor: COLOR_LIGHT,
centerColor: COLOR_PRIMARY,

// startAngle: Phaser.Math.DegToRad(270-45),
// endAngle: Phaser.Math.DegToRad(270+45),
// anticlockwise: true,

// textColor: 0xffffff,
textStrokeColor: 'red',
textStrokeThickness: 3,
Expand Down
24 changes: 20 additions & 4 deletions plugins/gameobjects/canvas/circularprogress/CircularProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class CircularProgress extends ProgressBase(Canvas) {
value = NormalizeAngle(value);
this.dirty = this.dirty || (this._startAngle != value);
this._startAngle = value;
this._deltaAngle = GetDeltaAngle(this._startAngle, this._endAngle, this._anticlockwise);
}

setStartAngle(angle) {
Expand All @@ -154,12 +155,10 @@ class CircularProgress extends ProgressBase(Canvas) {
}

set endAngle(value) {
if (value < this.startAngle) {
value += PI2;
}

value = NormalizeAngle(value);
this.dirty = this.dirty || (this._endAngle != value);
this._endAngle = value;
this._deltaAngle = GetDeltaAngle(this._startAngle, this._endAngle, this._anticlockwise);
}

setEndAngle(angle) {
Expand All @@ -174,6 +173,7 @@ class CircularProgress extends ProgressBase(Canvas) {
set anticlockwise(value) {
this.dirty = this.dirty || (this._anticlockwise != value);
this._anticlockwise = value;
this._deltaAngle = GetDeltaAngle(this._startAngle, this._endAngle, this._anticlockwise);
}

setAnticlockwise(anticlockwise) {
Expand Down Expand Up @@ -316,4 +316,20 @@ class CircularProgress extends ProgressBase(Canvas) {
}
}

var GetDeltaAngle = function (startAngle, endAngle, anticlockwise) {
if (anticlockwise) {
if (startAngle <= endAngle) {
return (PI2 + startAngle) - endAngle;
} else {
return startAngle - endAngle;
}
} else {
if (startAngle >= endAngle) {
return (PI2 + endAngle) - startAngle;
} else {
return endAngle - startAngle;
}
}
}

export default CircularProgress;
10 changes: 7 additions & 3 deletions plugins/gameobjects/canvas/circularprogress/DrawContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var DrawContent = function () {
var anticlockwise = this.anticlockwise,
startAngle = this.startAngle,
endAngle = this.endAngle,
deltaAngle = endAngle - startAngle;
deltaAngle = this._deltaAngle;

// Draw track
if (this.trackColor && (lineWidth > 0)) {
Expand All @@ -35,8 +35,12 @@ var DrawContent = function () {

// Draw bar
if ((this.barColor) && (barRadius > 0)) {
var barDeltaAngle = deltaAngle * ((anticlockwise) ? (1 - this.value) : this.value);
var barEndAngle = barDeltaAngle + startAngle;
var barEndAngle;
if (anticlockwise) {
barEndAngle = (startAngle - (deltaAngle * this.value) + PI2) % PI2;
} else {
barEndAngle = (startAngle + deltaAngle * this.value) % PI2;
}

context.save();

Expand Down

0 comments on commit 55f5d7b

Please sign in to comment.