|
4 | 4 | * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} |
5 | 5 | */ |
6 | 6 |
|
| 7 | +var Clamp = require('../math/Clamp'); |
7 | 8 | var Class = require('../utils/Class'); |
| 9 | +var FindClosestInSorted = require('../utils/array/FindClosestInSorted'); |
8 | 10 | var Frame = require('./AnimationFrame'); |
9 | 11 | var GetValue = require('../utils/object/GetValue'); |
10 | 12 |
|
@@ -340,8 +342,8 @@ var Animation = new Class({ |
340 | 342 | */ |
341 | 343 | this.paused = false; |
342 | 344 |
|
343 | | - this.manager.on('pauseall', this.pause.bind(this)); |
344 | | - this.manager.on('resumeall', this.resume.bind(this)); |
| 345 | + this.manager.on('pauseall', this.pause, this); |
| 346 | + this.manager.on('resumeall', this.resume, this); |
345 | 347 | }, |
346 | 348 |
|
347 | 349 | /** |
@@ -632,6 +634,23 @@ var Animation = new Class({ |
632 | 634 | component.updateFrame(this.frames[startFrame]); |
633 | 635 | }, |
634 | 636 |
|
| 637 | + /** |
| 638 | + * Returns the frame closest to the given progress value between 0 and 1. |
| 639 | + * |
| 640 | + * @method Phaser.Animations.Animation#getFrameByProgress |
| 641 | + * @since 3.4.0 |
| 642 | + * |
| 643 | + * @param {float} value - A value between 0 and 1. |
| 644 | + * |
| 645 | + * @return {Phaser.Animations.AnimationFrame} [description] |
| 646 | + */ |
| 647 | + getFrameByProgress: function (value) |
| 648 | + { |
| 649 | + value = Clamp(value, 0, 1); |
| 650 | + |
| 651 | + return FindClosestInSorted(value, this.frames, 'progress'); |
| 652 | + }, |
| 653 | + |
635 | 654 | /** |
636 | 655 | * [description] |
637 | 656 | * |
@@ -927,7 +946,19 @@ var Animation = new Class({ |
927 | 946 | */ |
928 | 947 | destroy: function () |
929 | 948 | { |
930 | | - // TODO |
| 949 | + this.manager.off('pauseall', this.pause, this); |
| 950 | + this.manager.off('resumeall', this.resume, this); |
| 951 | + |
| 952 | + this.manager.remove(this.key); |
| 953 | + |
| 954 | + for (var i = 0; i < this.frames.length; i++) |
| 955 | + { |
| 956 | + this.frames[i].destroy(); |
| 957 | + } |
| 958 | + |
| 959 | + this.frames = []; |
| 960 | + |
| 961 | + this.manager = null; |
931 | 962 | } |
932 | 963 |
|
933 | 964 | }); |
|
0 commit comments