@@ -11,34 +11,34 @@ var Animation = function (manager, key, config)
1111 this . frames = GetFrames ( manager . textureManager , GetObjectValue ( config , 'frames' , [ ] ) ) ;
1212
1313 // The frame rate of playback in frames per second (default 24 if duration is null)
14- this . framerate = GetObjectValue ( config , 'framerate' , null ) ;
14+ this . frameRate = GetObjectValue ( config , 'framerate' , null ) ;
1515
16- // How long the animation should play for. If framerate is set it overrides this value
17- // otherwise framerate is derived from duration
16+ // How long the animation should play for. If frameRate is set it overrides this value
17+ // otherwise frameRate is derived from duration
1818 this . duration = GetObjectValue ( config , 'duration' , null ) ;
1919
20- if ( this . duration === null && this . framerate === null )
20+ if ( this . duration === null && this . frameRate === null )
2121 {
22- this . framerate = 24 ;
23- this . duration = this . framerate / this . frames . length ;
22+ this . frameRate = 24 ;
23+ this . duration = this . frameRate / this . frames . length ;
2424 }
25- else if ( this . duration && this . framerate === null )
25+ else if ( this . duration && this . frameRate === null )
2626 {
27- // Duration given but no framerate , so set the framerate based on duration
27+ // Duration given but no frameRate , so set the frameRate based on duration
2828 // I.e. 12 frames in the animation, duration = 4 (4000 ms)
29- // So framerate is 12 / 4 = 3 fps
30- this . framerate = this . frames . length / this . duration ;
29+ // So frameRate is 12 / 4 = 3 fps
30+ this . frameRate = this . frames . length / this . duration ;
3131 }
3232 else
3333 {
34- // No duration, so derive from the framerate
35- // I.e. 15 frames in the animation, framerate = 30 fps
34+ // No duration, so derive from the frameRate
35+ // I.e. 15 frames in the animation, frameRate = 30 fps
3636 // So duration is 15 / 30 = 0.5 (half a second)
37- this . duration = this . frames . length / this . framerate ;
37+ this . duration = this . frames . length / this . frameRate ;
3838 }
3939
4040 // ms per frame (without including frame specific modifiers)
41- this . msPerFrame = 1000 / this . framerate ;
41+ this . msPerFrame = 1000 / this . frameRate ;
4242
4343 // Skip frames if the time lags, or always advanced anyway?
4444 this . skipMissedFrames = GetObjectValue ( config , 'skipMissedFrames' , true ) ;
@@ -73,7 +73,21 @@ Animation.prototype = {
7373 startFrame = 0 ;
7474 }
7575
76- component . updateAnimation ( this ) ;
76+ if ( component . currentAnim !== this )
77+ {
78+ component . currentAnim = this ;
79+
80+ component . _timeScale = 1 ;
81+ component . frameRate = this . frameRate ;
82+ component . duration = this . duration ;
83+ component . msPerFrame = this . msPerFrame ;
84+ component . skipMissedFrames = this . skipMissedFrames ;
85+ component . _delay = this . delay ;
86+ component . _repeat = this . repeat ;
87+ component . _repeatDelay = this . repeatDelay ;
88+ component . _yoyo = this . yoyo ;
89+ }
90+
7791 component . updateFrame ( this . frames [ startFrame ] ) ;
7892 } ,
7993
@@ -88,19 +102,19 @@ Animation.prototype = {
88102
89103 // When is the first update due?
90104 component . accumulator = 0 ;
91- component . nextTick = this . msPerFrame + component . currentFrame . duration ;
105+ component . nextTick = component . msPerFrame + component . currentFrame . duration ;
92106
93107 if ( includeDelay )
94108 {
95- component . nextTick += ( this . delay * 1000 ) ;
109+ component . nextTick += ( component . _delay * 1000 ) ;
96110 }
97111 } ,
98112
99113 getNextTick : function ( component )
100114 {
101115 // When is the next update due?
102116 component . accumulator -= component . nextTick ;
103- component . nextTick = this . msPerFrame + component . currentFrame . duration ;
117+ component . nextTick = component . msPerFrame + component . currentFrame . duration ;
104118 } ,
105119
106120 nextFrame : function ( component )
@@ -117,6 +131,8 @@ Animation.prototype = {
117131 if ( this . yoyo )
118132 {
119133 component . forward = false ;
134+
135+ component . updateFrame ( frame . prevFrame ) ;
120136
121137 // Delay for the current frame
122138 this . getNextTick ( component ) ;
@@ -171,11 +187,11 @@ Animation.prototype = {
171187
172188 repeatAnimation : function ( component )
173189 {
174- if ( this . repeatDelay > 0 && component . pendingRepeat === false )
190+ if ( component . _repeatDelay > 0 && component . pendingRepeat === false )
175191 {
176192 component . pendingRepeat = true ;
177193 component . accumulator -= component . nextTick ;
178- component . nextTick += ( this . repeatDelay * 1000 ) ;
194+ component . nextTick += ( component . _repeatDelay * 1000 ) ;
179195 }
180196 else
181197 {
0 commit comments