Skip to content

Commit 20c230d

Browse files
committed
Added Animation.delay, repeat and repeatDelay, and fixed scoping issues and return values.
1 parent 98fa6ec commit 20c230d

15 files changed

Lines changed: 114 additions & 26 deletions

File tree

v3/src/animation/frame/Animation.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ Animation.prototype = {
8282
component.duration = this.duration;
8383
component.msPerFrame = this.msPerFrame;
8484
component.skipMissedFrames = this.skipMissedFrames;
85-
component.delay = this.delay;
86-
component.repeat = this.repeat;
87-
component.repeatDelay = this.repeatDelay;
88-
component.yoyo = this.yoyo;
85+
component._delay = this.delay;
86+
component._repeat = this.repeat;
87+
component._repeatDelay = this.repeatDelay;
88+
component._yoyo = this.yoyo;
8989
}
9090

9191
component.updateFrame(this.frames[startFrame]);
@@ -106,7 +106,7 @@ Animation.prototype = {
106106

107107
if (includeDelay)
108108
{
109-
component.nextTick += (component.delay * 1000);
109+
component.nextTick += (component._delay * 1000);
110110
}
111111
},
112112

@@ -187,11 +187,11 @@ Animation.prototype = {
187187

188188
repeatAnimation: function (component)
189189
{
190-
if (component.repeatDelay > 0 && component.pendingRepeat === false)
190+
if (component._repeatDelay > 0 && component.pendingRepeat === false)
191191
{
192192
component.pendingRepeat = true;
193193
component.accumulator -= component.nextTick;
194-
component.nextTick += (component.repeatDelay * 1000);
194+
component.nextTick += (component._repeatDelay * 1000);
195195
}
196196
else
197197
{

v3/src/animation/frame/Delay.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Gets or sets the amount of time in seconds between repeats.
2+
// For example, if repeat is 2 and repeatDelay is 1, the animation will play initially,
3+
// then wait for 1 second before it repeats, then play again, then wait 1 second again
4+
// before doing its final repeat.
5+
6+
var Delay = function (value)
7+
{
8+
if (value === undefined)
9+
{
10+
return this._delay;
11+
}
12+
else
13+
{
14+
this._delay = value;
15+
16+
return this;
17+
}
18+
};
19+
20+
module.exports = Delay;

v3/src/animation/frame/DelayedPlay.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var DelayedPlay = function (delay, key, startFrame)
44

55
this.nextTick += (delay * 1000);
66

7-
return this.parent;
7+
return this;
88
};
99

1010
module.exports = DelayedPlay;

v3/src/animation/frame/Load.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ var Load = function (key, startFrame)
99

1010
// Load the new animation in
1111
this.animationManager.load(this, key, startFrame);
12+
13+
return this;
1214
};
1315

1416
module.exports = Load;

v3/src/animation/frame/Pause.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
var Pause = function ()
1+
var Pause = function (atFrame)
22
{
33
if (!this._paused)
44
{
55
this._paused = true;
66
this._wasPlaying = this.isPlaying;
77
this.isPlaying = false;
88
}
9+
10+
if (atFrame !== undefined)
11+
{
12+
this.updateFrame(atFrame);
13+
}
914

1015
return this;
1116
};

v3/src/animation/frame/Play.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var Play = function (key, startFrame)
55
this.load(key, startFrame);
66

77
// Should give us 9,007,199,254,740,991 safe repeats
8-
this.repeatCounter = (this.repeat === -1) ? Number.MAX_SAFE_INTEGER : this.repeat;
8+
this.repeatCounter = (this._repeat === -1) ? Number.MAX_SAFE_INTEGER : this._repeat;
99

1010
this.currentAnim.getFirstTick(this);
1111

@@ -15,7 +15,7 @@ var Play = function (key, startFrame)
1515

1616
this.prevTick = this.mainloop.lastFrameTimeMs;
1717

18-
return this.parent;
18+
return this;
1919
};
2020

2121
module.exports = Play;

v3/src/animation/frame/Progress.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
// Value between 0 and 1. How far this animation is through, ignoring repeats and yoyos.
22
// If the animation has a non-zero repeat defined, progress and totalProgress will be different
33
// because progress doesn't include any repeats or repeatDelays whereas totalProgress does.
4-
var Progress = function ()
4+
var Progress = function (value)
55
{
6-
var p = this.currentFrame.progress;
7-
8-
if (!this.forward)
6+
if (value === undefined)
97
{
10-
p = 1 - p;
8+
var p = this.currentFrame.progress;
9+
10+
if (!this.forward)
11+
{
12+
p = 1 - p;
13+
}
14+
15+
return p;
1116
}
17+
else
18+
{
19+
// TODO: Set progress
1220

13-
return p;
21+
return this;
22+
}
1423
};
1524

1625
module.exports = Progress;

v3/src/animation/frame/Repeat.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Gets or sets the number of times that the animation should repeat
2+
// after its first iteration. For example, if repeat is 1, the animation will
3+
// play a total of twice (the initial play plus 1 repeat).
4+
// To repeat indefinitely, use -1. repeat should always be an integer.
5+
6+
var Repeat = function (value)
7+
{
8+
if (value === undefined)
9+
{
10+
return this._repeat;
11+
}
12+
else
13+
{
14+
this._repeat = value;
15+
this.repeatCounter = 0;
16+
17+
return this;
18+
}
19+
};
20+
21+
module.exports = Repeat;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Gets or sets the amount of time in seconds between repeats.
2+
// For example, if repeat is 2 and repeatDelay is 1, the animation will play initially,
3+
// then wait for 1 second before it repeats, then play again, then wait 1 second again
4+
// before doing its final repeat.
5+
6+
var RepeatDelay = function (value)
7+
{
8+
if (value === undefined)
9+
{
10+
return this._repeatDelay;
11+
}
12+
else
13+
{
14+
this._repeatDelay = value;
15+
16+
return this;
17+
}
18+
};
19+
20+
module.exports = RepeatDelay;

v3/src/animation/frame/Restart.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var Restart = function (includeDelay)
1313
// Set frame
1414
this.updateFrame(this.currentAnim.frames[0]);
1515

16-
return this.parent;
16+
return this;
1717
};
1818

1919
module.exports = Restart;

0 commit comments

Comments
 (0)