Skip to content

Commit 9368c80

Browse files
committed
getFrameByProgress will return the Animation Frame that is closest to the given progress value.
1 parent 9f85c0f commit 9368c80

1 file changed

Lines changed: 34 additions & 3 deletions

File tree

src/animations/Animation.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
55
*/
66

7+
var Clamp = require('../math/Clamp');
78
var Class = require('../utils/Class');
9+
var FindClosestInSorted = require('../utils/array/FindClosestInSorted');
810
var Frame = require('./AnimationFrame');
911
var GetValue = require('../utils/object/GetValue');
1012

@@ -340,8 +342,8 @@ var Animation = new Class({
340342
*/
341343
this.paused = false;
342344

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);
345347
},
346348

347349
/**
@@ -632,6 +634,23 @@ var Animation = new Class({
632634
component.updateFrame(this.frames[startFrame]);
633635
},
634636

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+
635654
/**
636655
* [description]
637656
*
@@ -927,7 +946,19 @@ var Animation = new Class({
927946
*/
928947
destroy: function ()
929948
{
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;
931962
}
932963

933964
});

0 commit comments

Comments
 (0)