-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprogressbar.js
More file actions
46 lines (40 loc) · 1.55 KB
/
progressbar.js
File metadata and controls
46 lines (40 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
pc.script.create('progressbar', function (context) {
var Progressbar = function (entity) {
this.entity = entity;
this.progress = null;
this.foreground = null;
this.initialWidth = 0;
this.initialLeft = 0;
};
Progressbar.prototype = {
initialize: function () {
this.foreground = this.entity.findByName('Foreground').script.sprite;
this.initialWidth = this.foreground.width;
this.initialLeft = this.foreground.x;
this.setProgress(1);
},
setProgress: function (progress) {
progress = pc.math.clamp(progress, 0, 1);
if (this.progress !== progress) {
this.progress = progress;
this.foreground.width = pc.math.lerp(0, this.initialWidth, progress);
this.foreground.uPercentage = progress;
// position the foreground correctly depending on its alignment
switch (this.foreground.anchor) {
case 1:
case 4:
case 7:
this.foreground.x = this.initialLeft - (1 - progress) * this.initialWidth * 0.5;
break;
case 2:
case 5:
case 8:
this.foreground.x = this.initialLeft - (1 - progress) * this.initialWidth;
break;
}
this.foreground.updateSprite();
}
}
};
return Progressbar;
});