TweenManager.getTweensOf has a new parameter includePending. If set, it will also check the pending tweens for the given targets and return those in the results as well. Fix #5260

This commit is contained in:
Richard Davey 2020-08-20 10:22:35 +01:00
parent ab605eed78
commit 8c55fc7ee2

View file

@ -541,27 +541,39 @@ var TweenManager = new Class({
/**
* Returns an array of all Tweens or Timelines in the Tween Manager which affect the given target or array of targets.
*
* Only the currently active tweens are tested. A tween that has completed and is
* awaiting removal will not be included in the results.
*
* If you wish to also search pending tweens, use the `includePending` flag.
*
* @method Phaser.Tweens.TweenManager#getTweensOf
* @since 3.0.0
*
* @param {(object|array)} target - The target to look for. Provide an array to look for multiple targets.
* @param {boolean} [includePending=false] - Also check for pending tweens, not just active ones?
*
* @return {Phaser.Tweens.Tween[]} A new array containing all Tweens and Timelines which affect the given target(s).
*/
getTweensOf: function (target)
getTweensOf: function (target, includePending)
{
if (includePending === undefined) { includePending = false; }
var list = this._active;
var tween;
var output = [];
var i;
var t;
if (Array.isArray(target))
if (!Array.isArray(target))
{
target = [ target ];
}
for (i = 0; i < list.length; i++)
{
tween = list[i];
for (var t = 0; t < target.length; t++)
for (t = 0; t < target.length; t++)
{
if (tween.hasTarget(target[t]))
{
@ -569,19 +581,24 @@ var TweenManager = new Class({
}
}
}
}
else
if (includePending)
{
list = this._pending;
for (i = 0; i < list.length; i++)
{
tween = list[i];
if (tween.hasTarget(target))
for (t = 0; t < target.length; t++)
{
if (tween.hasTarget(target[t]))
{
output.push(tween);
}
}
}
}
return output;
},