-
Notifications
You must be signed in to change notification settings - Fork 193
/
Copy pathsrc_components_AnimationManager.ts.html
864 lines (638 loc) · 35.1 KB
/
src_components_AnimationManager.ts.html
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>src\components\AnimationManager.ts - Kiwi.js</title>
<link rel="stylesheet" href="http://yui.yahooapis.com/3.9.1/build/cssgrids/cssgrids-min.css">
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
<link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
<script src="http://yui.yahooapis.com/combo?3.9.1/build/yui/yui-min.js"></script>
</head>
<body class="yui3-skin-sam">
<div id="doc">
<div id="hd" class="yui3-g header">
<div class="yui3-u-3-4">
<h1><img src="../assets/css/logo.png" title="Kiwi.js"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 1.4.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
<div class="yui3-u-1-4">
<div id="docs-sidebar" class="sidebar apidocs">
<div id="api-list">
<h2 class="off-left">APIs</h2>
<div id="api-tabview" class="tabview">
<ul class="tabs">
<li><a href="#api-classes">Classes</a></li>
<li><a href="#api-modules">Modules</a></li>
</ul>
<div id="api-tabview-filter">
<input type="search" id="api-filter" placeholder="Type to filter APIs">
</div>
<div id="api-tabview-panel">
<ul id="api-classes" class="apis classes">
<li><a href="../classes/Kiwi.Animations.Animation.html">Kiwi.Animations.Animation</a></li>
<li><a href="../classes/Kiwi.Animations.Sequence.html">Kiwi.Animations.Sequence</a></li>
<li><a href="../classes/Kiwi.Animations.Tween.html">Kiwi.Animations.Tween</a></li>
<li><a href="../classes/Kiwi.Animations.Tweens.Easing.Back.html">Kiwi.Animations.Tweens.Easing.Back</a></li>
<li><a href="../classes/Kiwi.Animations.Tweens.Easing.Bounce.html">Kiwi.Animations.Tweens.Easing.Bounce</a></li>
<li><a href="../classes/Kiwi.Animations.Tweens.Easing.Circular.html">Kiwi.Animations.Tweens.Easing.Circular</a></li>
<li><a href="../classes/Kiwi.Animations.Tweens.Easing.Cubic.html">Kiwi.Animations.Tweens.Easing.Cubic</a></li>
<li><a href="../classes/Kiwi.Animations.Tweens.Easing.Elastic.html">Kiwi.Animations.Tweens.Easing.Elastic</a></li>
<li><a href="../classes/Kiwi.Animations.Tweens.Easing.Exponential.html">Kiwi.Animations.Tweens.Easing.Exponential</a></li>
<li><a href="../classes/Kiwi.Animations.Tweens.Easing.Linear.html">Kiwi.Animations.Tweens.Easing.Linear</a></li>
<li><a href="../classes/Kiwi.Animations.Tweens.Easing.Quadratic.html">Kiwi.Animations.Tweens.Easing.Quadratic</a></li>
<li><a href="../classes/Kiwi.Animations.Tweens.Easing.Quartic.html">Kiwi.Animations.Tweens.Easing.Quartic</a></li>
<li><a href="../classes/Kiwi.Animations.Tweens.Easing.Quintic.html">Kiwi.Animations.Tweens.Easing.Quintic</a></li>
<li><a href="../classes/Kiwi.Animations.Tweens.Easing.Sinusoidal.html">Kiwi.Animations.Tweens.Easing.Sinusoidal</a></li>
<li><a href="../classes/Kiwi.Animations.Tweens.TweenManager.html">Kiwi.Animations.Tweens.TweenManager</a></li>
<li><a href="../classes/Kiwi.Camera.html">Kiwi.Camera</a></li>
<li><a href="../classes/Kiwi.CameraManager.html">Kiwi.CameraManager</a></li>
<li><a href="../classes/Kiwi.Component.html">Kiwi.Component</a></li>
<li><a href="../classes/Kiwi.ComponentManager.html">Kiwi.ComponentManager</a></li>
<li><a href="../classes/Kiwi.Components.AnimationManager.html">Kiwi.Components.AnimationManager</a></li>
<li><a href="../classes/Kiwi.Components.ArcadePhysics.html">Kiwi.Components.ArcadePhysics</a></li>
<li><a href="../classes/Kiwi.Components.Box.html">Kiwi.Components.Box</a></li>
<li><a href="../classes/Kiwi.Components.Input.html">Kiwi.Components.Input</a></li>
<li><a href="../classes/Kiwi.Components.Sound.html">Kiwi.Components.Sound</a></li>
<li><a href="../classes/Kiwi.Entity.html">Kiwi.Entity</a></li>
<li><a href="../classes/Kiwi.Files.AudioFile.html">Kiwi.Files.AudioFile</a></li>
<li><a href="../classes/Kiwi.Files.DataFile.html">Kiwi.Files.DataFile</a></li>
<li><a href="../classes/Kiwi.Files.DataLibrary.html">Kiwi.Files.DataLibrary</a></li>
<li><a href="../classes/Kiwi.Files.File.html">Kiwi.Files.File</a></li>
<li><a href="../classes/Kiwi.Files.FileStore.html">Kiwi.Files.FileStore</a></li>
<li><a href="../classes/Kiwi.Files.Loader.html">Kiwi.Files.Loader</a></li>
<li><a href="../classes/Kiwi.Files.TextureFile.html">Kiwi.Files.TextureFile</a></li>
<li><a href="../classes/Kiwi.Game.html">Kiwi.Game</a></li>
<li><a href="../classes/Kiwi.GameManager.html">Kiwi.GameManager</a></li>
<li><a href="../classes/Kiwi.GameObjects.Sprite.html">Kiwi.GameObjects.Sprite</a></li>
<li><a href="../classes/Kiwi.GameObjects.StaticImage.html">Kiwi.GameObjects.StaticImage</a></li>
<li><a href="../classes/Kiwi.GameObjects.TextField.html">Kiwi.GameObjects.TextField</a></li>
<li><a href="../classes/Kiwi.GameObjects.Tilemap.TileMap.html">Kiwi.GameObjects.Tilemap.TileMap</a></li>
<li><a href="../classes/Kiwi.GameObjects.Tilemap.TileMapLayer.html">Kiwi.GameObjects.Tilemap.TileMapLayer</a></li>
<li><a href="../classes/Kiwi.GameObjects.Tilemap.TileMapLayerIsometric.html">Kiwi.GameObjects.Tilemap.TileMapLayerIsometric</a></li>
<li><a href="../classes/Kiwi.GameObjects.Tilemap.TileMapLayerOrthogonal.html">Kiwi.GameObjects.Tilemap.TileMapLayerOrthogonal</a></li>
<li><a href="../classes/Kiwi.GameObjects.Tilemap.TileType.html">Kiwi.GameObjects.Tilemap.TileType</a></li>
<li><a href="../classes/Kiwi.Geom.AABB.html">Kiwi.Geom.AABB</a></li>
<li><a href="../classes/Kiwi.Geom.Circle.html">Kiwi.Geom.Circle</a></li>
<li><a href="../classes/Kiwi.Geom.Intersect.html">Kiwi.Geom.Intersect</a></li>
<li><a href="../classes/Kiwi.Geom.IntersectResult.html">Kiwi.Geom.IntersectResult</a></li>
<li><a href="../classes/Kiwi.Geom.Line.html">Kiwi.Geom.Line</a></li>
<li><a href="../classes/Kiwi.Geom.Matrix.html">Kiwi.Geom.Matrix</a></li>
<li><a href="../classes/Kiwi.Geom.Point.html">Kiwi.Geom.Point</a></li>
<li><a href="../classes/Kiwi.Geom.Ray.html">Kiwi.Geom.Ray</a></li>
<li><a href="../classes/Kiwi.Geom.Rectangle.html">Kiwi.Geom.Rectangle</a></li>
<li><a href="../classes/Kiwi.Geom.Transform.html">Kiwi.Geom.Transform</a></li>
<li><a href="../classes/Kiwi.Geom.Vector2.html">Kiwi.Geom.Vector2</a></li>
<li><a href="../classes/Kiwi.Group.html">Kiwi.Group</a></li>
<li><a href="../classes/Kiwi.HUD.HUDComponents.Counter.html">Kiwi.HUD.HUDComponents.Counter</a></li>
<li><a href="../classes/Kiwi.HUD.HUDComponents.Time.html">Kiwi.HUD.HUDComponents.Time</a></li>
<li><a href="../classes/Kiwi.HUD.HUDComponents.WidgetInput.html">Kiwi.HUD.HUDComponents.WidgetInput</a></li>
<li><a href="../classes/Kiwi.HUD.HUDDisplay.html">Kiwi.HUD.HUDDisplay</a></li>
<li><a href="../classes/Kiwi.HUD.HUDManager.html">Kiwi.HUD.HUDManager</a></li>
<li><a href="../classes/Kiwi.HUD.HUDWidget.html">Kiwi.HUD.HUDWidget</a></li>
<li><a href="../classes/Kiwi.HUD.Widget.Bar.html">Kiwi.HUD.Widget.Bar</a></li>
<li><a href="../classes/Kiwi.HUD.Widget.BasicScore.html">Kiwi.HUD.Widget.BasicScore</a></li>
<li><a href="../classes/Kiwi.HUD.Widget.Button.html">Kiwi.HUD.Widget.Button</a></li>
<li><a href="../classes/Kiwi.HUD.Widget.Icon.html">Kiwi.HUD.Widget.Icon</a></li>
<li><a href="../classes/Kiwi.HUD.Widget.IconBar.html">Kiwi.HUD.Widget.IconBar</a></li>
<li><a href="../classes/Kiwi.HUD.Widget.Menu.html">Kiwi.HUD.Widget.Menu</a></li>
<li><a href="../classes/Kiwi.HUD.Widget.MenuItem.html">Kiwi.HUD.Widget.MenuItem</a></li>
<li><a href="../classes/Kiwi.HUD.Widget.TextField.html">Kiwi.HUD.Widget.TextField</a></li>
<li><a href="../classes/Kiwi.HUD.Widget.Time.html">Kiwi.HUD.Widget.Time</a></li>
<li><a href="../classes/Kiwi.IChild.html">Kiwi.IChild</a></li>
<li><a href="../classes/Kiwi.Input.Finger.html">Kiwi.Input.Finger</a></li>
<li><a href="../classes/Kiwi.Input.InputManager.html">Kiwi.Input.InputManager</a></li>
<li><a href="../classes/Kiwi.Input.Key.html">Kiwi.Input.Key</a></li>
<li><a href="../classes/Kiwi.Input.Keyboard.html">Kiwi.Input.Keyboard</a></li>
<li><a href="../classes/Kiwi.Input.Keycodes.html">Kiwi.Input.Keycodes</a></li>
<li><a href="../classes/Kiwi.Input.Mouse.html">Kiwi.Input.Mouse</a></li>
<li><a href="../classes/Kiwi.Input.MouseCursor.html">Kiwi.Input.MouseCursor</a></li>
<li><a href="../classes/Kiwi.Input.Pointer.html">Kiwi.Input.Pointer</a></li>
<li><a href="../classes/Kiwi.Input.Touch.html">Kiwi.Input.Touch</a></li>
<li><a href="../classes/Kiwi.PluginManager.html">Kiwi.PluginManager</a></li>
<li><a href="../classes/Kiwi.Renderers.CanvasRenderer.html">Kiwi.Renderers.CanvasRenderer</a></li>
<li><a href="../classes/Kiwi.Renderers.GLArrayBuffer.html">Kiwi.Renderers.GLArrayBuffer</a></li>
<li><a href="../classes/Kiwi.Renderers.GLBlendMode.html">Kiwi.Renderers.GLBlendMode</a></li>
<li><a href="../classes/Kiwi.Renderers.GLElementArrayBuffer.html">Kiwi.Renderers.GLElementArrayBuffer</a></li>
<li><a href="../classes/Kiwi.Renderers.GLRenderManager.html">Kiwi.Renderers.GLRenderManager</a></li>
<li><a href="../classes/Kiwi.Renderers.GLTextureManager.html">Kiwi.Renderers.GLTextureManager</a></li>
<li><a href="../classes/Kiwi.Renderers.GLTextureWrapper.html">Kiwi.Renderers.GLTextureWrapper</a></li>
<li><a href="../classes/Kiwi.Renderers.Renderer.html">Kiwi.Renderers.Renderer</a></li>
<li><a href="../classes/Kiwi.Renderers.TextureAtlasRenderer.html">Kiwi.Renderers.TextureAtlasRenderer</a></li>
<li><a href="../classes/Kiwi.Shaders.ShaderManager.html">Kiwi.Shaders.ShaderManager</a></li>
<li><a href="../classes/Kiwi.Shaders.ShaderPair.html">Kiwi.Shaders.ShaderPair</a></li>
<li><a href="../classes/Kiwi.Shaders.TextureAtlasShader.html">Kiwi.Shaders.TextureAtlasShader</a></li>
<li><a href="../classes/Kiwi.Signal.html">Kiwi.Signal</a></li>
<li><a href="../classes/Kiwi.SignalBinding.html">Kiwi.SignalBinding</a></li>
<li><a href="../classes/Kiwi.Sound.Audio.html">Kiwi.Sound.Audio</a></li>
<li><a href="../classes/Kiwi.Sound.AudioLibrary.html">Kiwi.Sound.AudioLibrary</a></li>
<li><a href="../classes/Kiwi.Sound.AudioManager.html">Kiwi.Sound.AudioManager</a></li>
<li><a href="../classes/Kiwi.Stage.html">Kiwi.Stage</a></li>
<li><a href="../classes/Kiwi.State.html">Kiwi.State</a></li>
<li><a href="../classes/Kiwi.StateConfig.html">Kiwi.StateConfig</a></li>
<li><a href="../classes/Kiwi.StateManager.html">Kiwi.StateManager</a></li>
<li><a href="../classes/Kiwi.System.Bootstrap.html">Kiwi.System.Bootstrap</a></li>
<li><a href="../classes/Kiwi.System.Device.html">Kiwi.System.Device</a></li>
<li><a href="../classes/Kiwi.Textures.SingleImage.html">Kiwi.Textures.SingleImage</a></li>
<li><a href="../classes/Kiwi.Textures.SpriteSheet.html">Kiwi.Textures.SpriteSheet</a></li>
<li><a href="../classes/Kiwi.Textures.TextureAtlas.html">Kiwi.Textures.TextureAtlas</a></li>
<li><a href="../classes/Kiwi.Textures.TextureLibrary.html">Kiwi.Textures.TextureLibrary</a></li>
<li><a href="../classes/Kiwi.Time.Clock.html">Kiwi.Time.Clock</a></li>
<li><a href="../classes/Kiwi.Time.ClockManager.html">Kiwi.Time.ClockManager</a></li>
<li><a href="../classes/Kiwi.Time.MasterClock.html">Kiwi.Time.MasterClock</a></li>
<li><a href="../classes/Kiwi.Time.Timer.html">Kiwi.Time.Timer</a></li>
<li><a href="../classes/Kiwi.Time.TimerEvent.html">Kiwi.Time.TimerEvent</a></li>
<li><a href="../classes/Kiwi.Utils.Canvas.html">Kiwi.Utils.Canvas</a></li>
<li><a href="../classes/Kiwi.Utils.Color.html">Kiwi.Utils.Color</a></li>
<li><a href="../classes/Kiwi.Utils.Common.html">Kiwi.Utils.Common</a></li>
<li><a href="../classes/Kiwi.Utils.GameMath.html">Kiwi.Utils.GameMath</a></li>
<li><a href="../classes/Kiwi.Utils.Log.html">Kiwi.Utils.Log</a></li>
<li><a href="../classes/Kiwi.Utils.RandomDataGenerator.html">Kiwi.Utils.RandomDataGenerator</a></li>
<li><a href="../classes/Kiwi.Utils.RequestAnimationFrame.html">Kiwi.Utils.RequestAnimationFrame</a></li>
<li><a href="../classes/Kiwi.Utils.Version.html">Kiwi.Utils.Version</a></li>
</ul>
<ul id="api-modules" class="apis modules">
<li><a href="../modules/Animations.html">Animations</a></li>
<li><a href="../modules/Components.html">Components</a></li>
<li><a href="../modules/Easing.html">Easing</a></li>
<li><a href="../modules/Files.html">Files</a></li>
<li><a href="../modules/GameObjects.html">GameObjects</a></li>
<li><a href="../modules/Geom.html">Geom</a></li>
<li><a href="../modules/HUD.html">HUD</a></li>
<li><a href="../modules/HUDComponents.html">HUDComponents</a></li>
<li><a href="../modules/Input.html">Input</a></li>
<li><a href="../modules/Kiwi.html">Kiwi</a></li>
<li><a href="../modules/Renderers.html">Renderers</a></li>
<li><a href="../modules/Shaders.html">Shaders</a></li>
<li><a href="../modules/Sound.html">Sound</a></li>
<li><a href="../modules/System.html">System</a></li>
<li><a href="../modules/Textures.html">Textures</a></li>
<li><a href="../modules/Tilemap.html">Tilemap</a></li>
<li><a href="../modules/Time.html">Time</a></li>
<li><a href="../modules/Tweens.html">Tweens</a></li>
<li><a href="../modules/Utils.html">Utils</a></li>
<li><a href="../modules/Utils..html">Utils.</a></li>
<li><a href="../modules/Widget.html">Widget</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="yui3-u-3-4">
<div id="api-options">
Show:
<label for="api-show-inherited">
<input type="checkbox" id="api-show-inherited" checked>
Inherited
</label>
<label for="api-show-protected">
<input type="checkbox" id="api-show-protected">
Protected
</label>
<label for="api-show-private">
<input type="checkbox" id="api-show-private">
Private
</label>
<label for="api-show-deprecated">
<input type="checkbox" id="api-show-deprecated">
Deprecated
</label>
</div>
<div class="apidocs">
<div id="docs-main">
<div class="content">
<h1 class="file-heading">File: src\components\AnimationManager.ts</h1>
<div class="file">
<pre class="code prettyprint linenums">
/**
* Component's are a snipnets of code which are designed to provide extra functionality to various objects that contain a ComponentManager. Objects do not have to have Components in order to preform their main function, but are instead provided to make common task's that you may want to do with those Objects a bit easier. For example: Some times you would like to easily listen for when a GameObject has been 'clicked'. So you can attach a 'InputComponent' to a GameObject (Sprites have them by default) which will then do hit-detector code for you. All you have to do is Subscribe to the events on the InputComponent.
*
* @module Kiwi
* @submodule Components
* @main Components
*/
module Kiwi.Components {
/**
* The AnimationManager is used to handle the creation and use of spritesheet Animations on a GameObject based on the TextureAtlas it has.
* If the When the AnimationManager is instantiated it will loop through all of the Sequences on the TextureAtlas of the GameObject being used and will create a new Animation for each one.
* Now when you create a new Animation that animation will automatically be added as a new Sequence to the corresponding Texture.
* This way you don't need to create new Animations for a each Sprite that use's the same Texture.
*
* @class AnimationManager
* @extends Kiwi.Component
* @namespace Kiwi.Components
* @constructor
* @param entity {Kiwi.Entity} The entity that this animation component belongs to.
* @param [inheritSequences=true] {Boolean} If a new Animation should be created for each Sequence on the Entities TextureAtlas it is a part of or not.
* @return {Kiwi.Components.AnimationManager}
*/
export class AnimationManager extends Component {
constructor(entity: Kiwi.Entity, inheritSequences: boolean = true) {
super(entity, 'Animation');
//Get the entity and the animation.
this.entity = entity;
this._atlas = this.entity.atlas;
this._animations = {};
//Create all of the default animations.
if (inheritSequences == true) {
for (var i = 0; i < this._atlas.sequences.length; i++) {
this.createFromSequence(this._atlas.sequences[i], false);
}
}
//If a default animation already exists
if (this._animations['default']) {
this.currentAnimation = this._animations['default'];
//Otherwise create one.
} else {
var defaultCells = [];
for (var i = 0; i < this._atlas.cells.length; i++) {
defaultCells.push(i);
}
this.currentAnimation = this.add('default', defaultCells, 0.1, true, false);
}
//Signals
this.onChange = new Kiwi.Signal;
this.onPlay = new Kiwi.Signal;
this.onStop = new Kiwi.Signal;
this.onUpdate = new Kiwi.Signal;
}
/**
* Dispatches callbacks each time an animation is told to play through this AnimationManager.
* Functions dispatched from this signal have ONE Parameter.
* One - The Animation object of that is now playing.
* @property onPlay
* @type Kiwi.Signal
* @public
*/
public onPlay: Kiwi.Signal;
/**
* Dispatches callbacks each time an animation stops.
* Functions dispatched from this signal have ONE parameter.
* One - The current animation.
* @property onStop
* @type Kiwi.Signal
* @public
*/
public onStop: Kiwi.Signal;
/**
* Dispatches callbacks each time the cell of the Sprite this AnimationManager belongs to updates/changes.
* Note: This method will be dispatching events EVERY time the cell changes, so this will include when changing/switching animations.
* @property onUpdate
* @type Kiwi.Signal
* @public
*/
public onUpdate: Kiwi.Signal
/**
* Dispatches callbacks each time the current animation is switched NOT when the cells of a animation change.
* Function's dispatched from this event have TWO parameters,
* One - Name of the animation switched to.
* Two - The Animation object that is now the current.
* @property onChange
* @type Kiwi.Signal
* @public
*/
public onChange: Kiwi.Signal;
/**
* The entity that this animation belongs to and thus is effecting.
* @property entity
* @type Kiwi.Entity
* @public
*/
public entity: Kiwi.Entity;
/**
* The texture atlas that this animation is taking effect on.
* The value of this should be the same as the Entity.
* @property _atlas
* @type Kiwi.Textures.TextureAtlas
* @private
*/
private _atlas: Kiwi.Textures.TextureAtlas;
/**
* A Object containing all of the animations that are avaiable to be used.
* @property _animations
* @type Object
* @private
*/
private _animations: {};
/**
* A reference to the animation that is currently being played.
* @property currentAnimation
* @type Kiwi.Animations.Animation
* @public
*/
public currentAnimation: Kiwi.Animations.Animation = null;
/**
* Returns a boolean indicating whether or not the current animation is playing. This is READ ONLY.
* @property isPlaying
* @type boolean
* @public
*/
public get isPlaying(): boolean {
return this.currentAnimation.isPlaying;
}
/**
* Returns a string indicating the type of object that this is.
* @method objType
* @return {String} "AnimationManager"
* @public
*/
public objType() {
return "AnimationManager";
}
/**
* Creates a new Animation (by creating a Sequence) that can then be played on this AnimationManager.
* If you pass to this the name of a Animation that already exists, then the previous Animation will be overridden by this new one.
* Note: If the Animation you have overridden was the currentAnimation, then the previous Animation will keep playing until a different Animation is switched to.
* By default new Animation Sequences are also added to the TextureAtlas, which can then be inherited.
* Returns the Animation that was created.
*
* @method add
* @param name {string} The name of the animation that is to be created.
* @param cells {Array} An array of numbers, which are reference to each cell that is to be played in the Animation in order.
* @param speed {number} The amount of time that each cell in the Animation should stay on screen for. In seconds.
* @param [loop=false] {boolean} If when the Animation reaches the last frame, it should go back to the start again.
* @param [play=false] {boolean} If once created the animation should played right away.
* @param [addToAtlas=true] {boolean} If the new Sequence created should be added to the TextureAtlas or not.
* @return {Kiwi.Animations.Animation} The Animation that was created.
* @public
*/
public add(name: string, cells: number[], speed: number, loop: boolean= false, play: boolean= false, addToAtlas:boolean=true): Kiwi.Animations.Animation {
var newSequence = new Kiwi.Animations.Sequence(name, cells, speed, loop);
if(addToAtlas == true) this._atlas.sequences.push(newSequence);
return this.createFromSequence(newSequence, play);
}
/**
* Creates a new Animation based on a Sequence that is passed.
* If you pass to this the name of a Animation that already exists, then the previous Animation will be overridden by this new one.
* Note: If the Animation you have overridden was the currentAnimation, then the previous Animation will keep playing until a different Animation is switched to.
* Returns the Animation that was created.
*
* @method createFromSequence
* @param sequence {Kiwi.Sequence} The sequence that the Animation is based on.
* @param [play=false] {boolean} If the Animation should played once it has been created
* @return {Kiwi.Animations.Animation} The Animation that was created.
* @public
*/
public createFromSequence(sequence: Kiwi.Animations.Sequence, play: boolean= false): Kiwi.Animations.Animation {
this._animations[sequence.name] = new Kiwi.Animations.Animation(sequence.name, sequence, null, this);
if (play) this.play(sequence.name);
return this._animations[sequence.name];
}
/**
* Plays either the current animation or the name of the animation that you pass.
*
* @method play
* @param [name] {String} The name of the animation that you want to play. If not passed it plays the current animation.
* @param [resetTime=true] {Boolean} When set to false, this will prevent a new Animation from playing if it is already the currentAnimation that is already playing.
* @return {Kiwi.Animations.Animation} Returns the current Animation that is now playing.
* @public
*/
public play(name: string = this.currentAnimation.name, resetTime: boolean = true): Kiwi.Animations.Animation {
//If the current animation playing
if (resetTime == false && this.currentAnimation.name === name && this.currentAnimation.isPlaying == true) {
return this.currentAnimation;
} else {
return this._play(name);
}
}
/**
* Plays an Animation at a particular frameIndex.
* Note: The frameIndex is a particular index of a cell in the Sequence of the Animation you would like to play.
* Example: If you had a Animation with a Sequence [0, 1, 2, 3] and you told it to play at index '2', then the cell that it would be at is '3'.
*
* @method playAt
* @param index {Number} The index of the frame in the Sequence that you would like to play.
* @param [name] {String} The name of the animation that you want to play. If not passed, it attempts to play it on the current animation.
* @return {Kiwi.Animations.Animation} Returns the current Animation that is now playing.
* @public
*/
public playAt(index: number, name: string = this.currentAnimation.name): Kiwi.Animations.Animation {
return this._play(name, index);
}
/**
* An internal method used to actually play a Animation at a Index.
*
* @method _play
* @param name {string} The name of the animation that is to be switched to.
* @param [index=null] {number} The index of the frame in the Sequence that is to play. If null, then it restarts the animation at the cell it currently is at.
* @return {Kiwi.Animations.Animation} Returns the current Animation that is now playing.
* @private
*/
private _play(name: string, index: number=null): Kiwi.Animations.Animation {
this._setCurrentAnimation(name);
if (index !== null)
this.currentAnimation.playAt(index);
else
this.currentAnimation.play();
this.onPlay.dispatch(this.currentAnimation);
this.updateCellIndex();
return this.currentAnimation;
}
/**
* Stops the current animation from playing.
*
* @method stop
* @public
*/
public stop() {
if (this.isPlaying === true) {
this.currentAnimation.stop();
this.onStop.dispatch(this.currentAnimation);
}
}
/**
* Pauses the current animation.
* @method pause
* @public
*/
public pause() {
this.currentAnimation.pause();
}
/**
* Resumes the current animation.
* The animation should have already been paused.
*
* @method resume
* @public
*/
public resume() {
this.currentAnimation.resume();
}
/**
* Either switches to a particular animation OR a particular frame in the current animation depending on if you pass the name of an animation that exists on this Manager (as a string) or a number refering to a frame index on the Animation.
* When you switch to a particular animation then
* You can also force the animation to play or to stop by passing a boolean in. But if left as null, the state of the Animation will based off what is currently happening.
* So if the animation is currently 'playing' then once switched to the animation will play. If not currently playing it will switch to and stop.
* If the previous animation played is non-looping and has reached its final frame, it is no longer considered playing, and as such, switching to another animation will not play unless the argument to the play parameter is true.
*
* @method switchTo
* @param val {string|number}
* @param [play=null] {boolean} Force the animation to play or stop. If null the animation base's it off what is currently happening.
* @public
*/
public switchTo(val: any, play:boolean=null) {
var switched = false;
switch (typeof val) {
case "string":
if (this.currentAnimation.name !== val) {
this._setCurrentAnimation(val);
switched = true;
}
break;
case "number":
this.currentAnimation.frameIndex = val;
switched = true;
break;
}
//Play if the dev forced it to OR if the animation was already playing
if (play || play === null && this.isPlaying && switched) this.play();
if (play == false && this.isPlaying) this.stop();
this.updateCellIndex();
}
/**
* Makes the current animation go to the next frame. If the animation is at the end of the sequence it then goes back to the start.
* @method nextFrame
* @public
*/
public nextFrame() {
this.currentAnimation.nextFrame();
this.updateCellIndex();
}
/**
* Makes the current animation go to the prev frame. If the animation is at the start, the animation will go the end of the sequence.
* @method prevFrame
* @public
*/
public prevFrame() {
this.currentAnimation.prevFrame();
this.updateCellIndex();
}
/**
* Internal method that sets the current animation to a Animation passed.
*
* @method _setCurrentAnimation
* @param name {string} Name of the Animation that is to be switched to.
* @param [inheritFromTexture=true] {booelan} If the animation component should look on the texture atlas for a sequence with that name.
* @private
*/
private _setCurrentAnimation(name: string, inheritFromTexture: boolean=true) {
if (this.currentAnimation.name !== name) {
if ( this.currentAnimation !== null ) this.currentAnimation.stop();
if (this._animations[name]) {
//Switch to the animation if it exists
this.currentAnimation = this._animations[name];
this.onChange.dispatch(name, this.currentAnimation);
} else if (inheritFromTexture) {
//Check to see if that animation exists on the atlas.
//If so create a new version of it.
for (var i = 0; i < this._atlas.sequences.length; i++) {
if (this._atlas.sequences[i].name === name) {
this.currentAnimation = this.createFromSequence(this._atlas.sequences[i], false);
this.onChange.dispatch(name, this.currentAnimation);
}
}
}
}
}
/**
* The update loop for this component.
* Only updates the currentAnimation and only if it is playing.
*
* @method update
* @public
*/
public update() {
if (this.currentAnimation) {
this.currentAnimation.update();
}
}
/**
* Gets the cell that the current Animation is current at. This is READ ONLY.
* @property currentCell
* @type number
* @public
*/
public get currentCell():number {
return this.currentAnimation.currentCell;
}
/**
* Gets the current frame index of the cell in the Sequence that is currently playing. This is READ ONLY.
* @property frameIndex
* @type number
* @public
*/
public get frameIndex():number {
return this.currentAnimation.frameIndex;
}
/**
* Returns the length (Number of cells) of the current Animation that is playing. This is READ ONLY.
* @property length
* @type number
* @public
*/
public get length(): number {
return this.currentAnimation.length;
}
/**
* Returns a Animation that is on this AnimationComponent
* Does not check to see if that Animation exists or not.
*
* @method getAnimation
* @param name {string} The name of the Animation you would like to get.
* @return {Kiwi.Animations.Animation} The Animation that is found. Will be 'undefined' if a Animation with that name did not exist.
* @public
*/
public getAnimation(name: string): Kiwi.Animations.Animation {
return this._animations[name];
}
/**
* An internal method that is used to update the cell index of an entity when an animation says it needs to update.
* @method updateCellIndex
* @protected
*/
public updateCellIndex() {
if (typeof this.currentAnimation !== "undefined") {
this.entity.cellIndex = this.currentAnimation.currentCell;
this.onUpdate.dispatch(this.currentAnimation);
}
}
/**
* Destroys the animation component and runs the destroy method on all of the anims that it has.
* @method destroy
* @public
*/
public destroy() {
super.destroy();
for (var key in this._animations) {
this._animations[key].destroy();
delete this._animations[key];
}
delete this._animations;
delete this.currentAnimation;
delete this._atlas;
}
}
}
</pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>
<script src="../assets/js/yui-prettify.js"></script>
<script src="../assets/../api.js"></script>
<script src="../assets/js/api-filter.js"></script>
<script src="../assets/js/api-list.js"></script>
<script src="../assets/js/api-search.js"></script>
<script src="../assets/js/apidocs.js"></script>
</body>
</html>