Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cancelTweensOf and completeTweensOf #2273

Merged
merged 18 commits into from
Nov 14, 2020
Merged

Conversation

Geokureli
Copy link
Member

@Geokureli Geokureli commented Oct 15, 2020

Added the ability to cancel or complete specific tweens without needing a reference to the tweens themselves. Useful when multiple things are applying tweens to the same object and want to remain agnostic of each other.

Usage:

FlxTween.tween(mySprite, { color: FlxColor.BLACK }, 1.0);

//... elsewhere ...
FlxTween.cancelTweensOf(mySprite);

// or, to only cancel color tweens on mySprite
FlxTween.cancelTweensOf(mySprite, "color");

also works with tweens that are not VarTweens by treating them as VarTweens based on the properties they change, such as:
AngleTween: "angle":
ColorTween: "color"
Motion (and all derivatives): "x" and "y"

completeTweensOf works identical, but finishes the tween and calls onComplete

Just like with VarTweens, properties passed in can be dot paths to denote properties of children, this way any field passed in to a var tween can be used to cancel or complete the tween
Example:

// either
FlxTween.tween(mySprite, { "child.color": FlxColor.BLACK }, 1.0);
// or
FlxTween.color(mySprite.child, 1.0, FlxColor.BLACK, FlxColor.RED);

// can be cancelled via:
FlxTween.cancelTweensOf(mySprite, ["child.color"]);
// or
FlxTween.cancelTweensOf(mySprite.child, ["color"]);

fixes #2180

flixel/tweens/FlxTween.hx Outdated Show resolved Hide resolved
flixel/tweens/FlxTween.hx Show resolved Hide resolved
@@ -37,6 +37,7 @@ class VarTween extends FlxTween
_propertyInfos = [];
this.duration = duration;
start();
initializeVars();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are any of the changes in VarTween changes besides the isTweenOf() override related to this PR? It's not clear to me why they were made.

Copy link
Member Author

@Geokureli Geokureli Nov 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It calls initializeVars earlier than before so that we can search _propertyInfos in isTweenOf() while that tween is in the delay phase. originally, this initialization was delayed until the tween starts so that chaining works correctly, but that delay is only needed for the startValues.

If you think I need to explain this in code, let me know

flixel/tweens/FlxTween.hx Outdated Show resolved Hide resolved
flixel/tweens/misc/VarTween.hx Outdated Show resolved Hide resolved
flixel/tweens/FlxTween.hx Outdated Show resolved Hide resolved
@Gama11 Gama11 merged commit a3ad1ed into HaxeFlixel:dev Nov 14, 2020
@Geokureli Geokureli deleted the killTweensOf branch January 24, 2022 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

killTweensOf
2 participants