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

FlxTween#cancelTweensOf(), closes #1458 #1495

Closed
wants to merge 4 commits into from
Closed

FlxTween#cancelTweensOf(), closes #1458 #1495

wants to merge 4 commits into from

Conversation

MSGhero
Copy link
Member

@MSGhero MSGhero commented May 10, 2015

#1458

I chose to make it manual adding and removing/canceling tweens instead of automatic so performance wouldn't be affected.

Usage would be like

var tw = FlxTween.num(..., { onComplete : FlxTween.unregisterTween.bind(_, this) }, ...);
FlxTween.registerTween(tw, this);

override public function destroy():Void {
     super.destroy();
     FlxTween.cancelTweensOf(this);
}

MSGhero added 4 commits May 4, 2015 00:11
for when an object is destroyed before any dependent tweens are
completed.
You have to manually call the functions. Better for performance than
automatically doing it.
Static methods and compile fixes
@Gama11
Copy link
Member

Gama11 commented May 10, 2015

Looks useful, but at the same time it seems like a somewhat awkward workaround for tweens not being added to FlxBasic / FlxObject in the first place (which would also solve issues regarding substate pausing etc discusses in #1087). That would be quite a big refactor though...

@MSGhero
Copy link
Member Author

MSGhero commented May 10, 2015

Yeah @Beeblerox said this would be part of a refactor later on. I need the functionality now, and I figured I'd post how I did it.

@JoeCreates
Copy link
Member

I use something along these lines to ensure I don't have multiple tweens fighting over the same object. The implementation of mapping objects to a tween in the same, but I also have an exclusiveTween method, which is identical to FlxTween.tween except you also pass it the dynamic key. When you exclusiveTween something, it automatically cancels the tweens with the same key.

This prevents things jittering and breaking when you, for example, have a tween pan the camera from one scene to another, but the user presses a button to tween back to the first scene before the first tween has finished.

Could this perhaps be worked into flixel, too?

@MSGhero
Copy link
Member Author

MSGhero commented May 19, 2015

@JoeCreates How do you remove the key-val of the tween ends normally? Do you search through all the pairs looking or is it manual?

I had something automatic like that, but it didn't seem very performant.

@Gama11 Gama11 modified the milestone: 4.0.0 May 30, 2015
@JoeCreates
Copy link
Member

@MSGhero I didn't automate the removal. For the most past I just left the tweens in the map even after they were finished, seeing as it's fine to cancel an already finished tween. I haven't had any need to remove them, yet, seeing as I have mainly used this for UI with a finite number of elements, and so the map is generally small. It's useful to be able to manually remove them, of course. I just haven't needed to remove them at all , yet.

@MSGhero
Copy link
Member Author

MSGhero commented May 30, 2015

I was thinking in terms of garbage collection. You have the tween and the object it references chilling in the map.

@JoeCreates
Copy link
Member

@MSGhero It's not something I've needed to consider yet, due to how frequently I reuse those objects.

@MSGhero
Copy link
Member Author

MSGhero commented Jul 2, 2015

I don't like this pull anymore. I'll leave #1458 up so it gets remembered, but I don't think anyone wants to have to bind a function and waste an onComplete to use it.

A proper way to do this should be a lazily created "tween manager" inside of each FlxObject and maybe an optional AddTweenTo:FlxObject parameter in the tween methods. Idk. 4.0.0 stuff.

@MSGhero MSGhero closed this Jul 2, 2015
@Gama11 Gama11 mentioned this pull request Dec 22, 2015
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.

3 participants