@@ -100,32 +100,22 @@ Animation.prototype.constructor = Animation;
100100
101101Animation . prototype = {
102102
103- load : function ( component , startFrame )
104- {
105- if ( startFrame >= this . frames . length )
106- {
107- startFrame = 0 ;
108- }
109-
110- if ( component . currentAnim !== this )
111- {
112- component . currentAnim = this ;
113-
114- component . _timeScale = 1 ;
115- component . frameRate = this . frameRate ;
116- component . duration = this . duration ;
117- component . msPerFrame = this . msPerFrame ;
118- component . skipMissedFrames = this . skipMissedFrames ;
119- component . _delay = this . delay ;
120- component . _repeat = this . repeat ;
121- component . _repeatDelay = this . repeatDelay ;
122- component . _yoyo = this . yoyo ;
123- component . _callbackArgs [ 1 ] = this ;
124- component . _updateParams = component . _callbackArgs . concat ( this . onUpdateParams ) ;
125- }
126-
127- component . updateFrame ( this . frames [ startFrame ] ) ;
128- } ,
103+ load : require ( './Load' ) ,
104+ addFrame : require ( './AddFrame' ) ,
105+ addFrameAt : require ( './AddFrameAt' ) ,
106+ getFrameAt : require ( './GetFrameAt' ) ,
107+ removeFrame : require ( './RemoveFrame' ) ,
108+ removeFrameAt : require ( './RemoveFrameAt' ) ,
109+ updateFrameSequence : require ( './UpdateFrameSequence' ) ,
110+ checkFrame : require ( './CheckFrame' ) ,
111+ getFirstTick : require ( './GetFirstTick' ) ,
112+ getNextTick : require ( './GetNextTick' ) ,
113+ nextFrame : require ( './NextFrame' ) ,
114+ previousFrame : require ( './PreviousFrame' ) ,
115+ repeatAnimation : require ( './RepeatAnimation' ) ,
116+ completeAnimation : require ( './CompleteAnimation' ) ,
117+ setFrame : require ( './SetFrame' ) ,
118+ toJSON : require ( './ToJSON' ) ,
129119
130120 pause : function ( )
131121 {
@@ -137,279 +127,6 @@ Animation.prototype = {
137127 this . paused = false ;
138128 } ,
139129
140- // config = Array of Animation config objects, like:
141- // [
142- // { key: 'gems', frame: 'diamond0001', [duration], [visible], [onUpdate] }
143- // ]
144-
145- // Add frames to the end of the animation
146- addFrame : function ( config )
147- {
148- return this . addFrameAt ( this . frames . length , config ) ;
149- } ,
150-
151- // Add frame/s into the animation
152- addFrameAt : function ( index , config )
153- {
154- if ( index === undefined ) { index = 0 ; }
155-
156- var newFrames = GetFrames ( this . manager . textureManager , config ) ;
157-
158- if ( newFrames . length === 0 )
159- {
160- if ( index === 0 )
161- {
162- this . frames = newFrames . concat ( this . frames ) ;
163- }
164- else if ( index === this . frames . length )
165- {
166- this . frames = this . frames . concat ( newFrames ) ;
167- }
168- else
169- {
170- var pre = this . frames . slice ( 0 , index ) ;
171- var post = this . frames . slice ( index ) ;
172-
173- this . frames = pre . concat ( newFrames , post ) ;
174- }
175-
176- this . updateFrameSequence ( ) ;
177- }
178-
179- return this ;
180- } ,
181-
182- getFrameAt : function ( index )
183- {
184- return this . frames [ index ] ;
185- } ,
186-
187- // Remove frame if it matches the given frame
188- removeFrame : function ( frame )
189- {
190- var index = this . frames . indexOf ( frame ) ;
191-
192- if ( index !== - 1 )
193- {
194- this . removeFrameAt ( index ) ;
195- }
196-
197- return this ;
198- } ,
199-
200- removeFrameAt : function ( index )
201- {
202- this . frames . splice ( index , 1 ) ;
203-
204- this . updateFrameSequence ( ) ;
205-
206- return this ;
207- } ,
208-
209- updateFrameSequence : function ( )
210- {
211- var len = this . frames . length ;
212- var slice = 1 / ( len - 1 ) ;
213-
214- for ( var i = 0 ; i < len ; i ++ )
215- {
216- var frame = this . frames [ i ] ;
217-
218- frame . index = i + 1 ;
219- frame . isFirst = false ;
220- frame . isLast = false ;
221- frame . progress = i * slice ;
222-
223- if ( i === 0 )
224- {
225- frame . isFirst = true ;
226- frame . isLast = ( len === 1 ) ;
227- frame . prevFrame = this . frames [ len - 1 ] ;
228- frame . nextFrame = this . frames [ i + 1 ] ;
229- }
230- else if ( i === len - 1 )
231- {
232- frame . isLast = true ;
233- frame . prevFrame = this . frames [ len - 2 ] ;
234- frame . nextFrame = this . frames [ 0 ] ;
235- }
236- else if ( len > 1 )
237- {
238- frame . prevFrame = this . frames [ i - 1 ] ;
239- frame . nextFrame = this . frames [ i + 1 ] ;
240- }
241- }
242-
243- return this ;
244- } ,
245-
246- checkFrame : function ( index )
247- {
248- return ( index < this . frames . length ) ;
249- } ,
250-
251- getFirstTick : function ( component , includeDelay )
252- {
253- if ( includeDelay === undefined ) { includeDelay = true ; }
254-
255- // When is the first update due?
256- component . accumulator = 0 ;
257- component . nextTick = component . msPerFrame + component . currentFrame . duration ;
258-
259- if ( includeDelay )
260- {
261- component . nextTick += ( component . _delay * 1000 ) ;
262- }
263- } ,
264-
265- getNextTick : function ( component )
266- {
267- // When is the next update due?
268- component . accumulator -= component . nextTick ;
269- component . nextTick = component . msPerFrame + component . currentFrame . duration ;
270- } ,
271-
272- nextFrame : function ( component )
273- {
274- var frame = component . currentFrame ;
275-
276- // TODO: Add frame skip support
277-
278- if ( frame . isLast )
279- {
280- // We're at the end of the animation
281-
282- // Yoyo? (happens before repeat)
283- if ( this . yoyo )
284- {
285- component . forward = false ;
286-
287- component . updateFrame ( frame . prevFrame ) ;
288-
289- // Delay for the current frame
290- this . getNextTick ( component ) ;
291- }
292- else if ( component . repeatCounter > 0 )
293- {
294- // Repeat (happens before complete)
295- this . repeatAnimation ( component ) ;
296- }
297- else
298- {
299- this . completeAnimation ( component ) ;
300- }
301- }
302- else
303- {
304- component . updateFrame ( frame . nextFrame ) ;
305-
306- this . getNextTick ( component ) ;
307- }
308- } ,
309-
310- previousFrame : function ( component )
311- {
312- var frame = component . currentFrame ;
313-
314- // TODO: Add frame skip support
315-
316- if ( frame . isFirst )
317- {
318- // We're at the start of the animation
319-
320- if ( component . repeatCounter > 0 )
321- {
322- // Repeat (happens before complete)
323- this . repeatAnimation ( component ) ;
324- }
325- else
326- {
327- this . completeAnimation ( component ) ;
328- }
329- }
330- else
331- {
332- component . updateFrame ( frame . prevFrame ) ;
333-
334- this . getNextTick ( component ) ;
335- }
336- } ,
337-
338- repeatAnimation : function ( component )
339- {
340- if ( component . _repeatDelay > 0 && component . pendingRepeat === false )
341- {
342- component . pendingRepeat = true ;
343- component . accumulator -= component . nextTick ;
344- component . nextTick += ( component . _repeatDelay * 1000 ) ;
345- }
346- else
347- {
348- component . repeatCounter -- ;
349-
350- component . forward = true ;
351-
352- component . updateFrame ( component . currentFrame . nextFrame ) ;
353-
354- this . getNextTick ( component ) ;
355-
356- component . pendingRepeat = false ;
357-
358- if ( this . onRepeat )
359- {
360- this . onRepeat . apply ( this . callbackScope , component . _callbackArgs . concat ( this . onRepeatParams ) ) ;
361- }
362- }
363- } ,
364-
365- completeAnimation : function ( component )
366- {
367- if ( this . hideOnComplete )
368- {
369- component . parent . visible = false ;
370- }
371-
372- component . stop ( true ) ;
373- } ,
374-
375- setFrame : function ( component )
376- {
377- // Work out which frame should be set next on the child, and set it
378- if ( component . forward )
379- {
380- this . nextFrame ( component ) ;
381- }
382- else
383- {
384- this . previousFrame ( component ) ;
385- }
386- } ,
387-
388- toJSON : function ( )
389- {
390- var output = {
391- key : this . key ,
392- type : this . type ,
393- frames : [ ] ,
394- framerate : this . frameRate ,
395- duration : this . duration ,
396- skipMissedFrames : this . skipMissedFrames ,
397- delay : this . delay ,
398- repeat : this . repeat ,
399- repeatDelay : this . repeatDelay ,
400- yoyo : this . yoyo ,
401- showOnStart : this . showOnStart ,
402- hideOnComplete : this . hideOnComplete
403- } ;
404-
405- this . frames . forEach ( function ( frame )
406- {
407- output . frames . push ( frame . toJSON ( ) ) ;
408- } ) ;
409-
410- return output ;
411- } ,
412-
413130 destroy : function ( )
414131 {
415132
0 commit comments