-
Notifications
You must be signed in to change notification settings - Fork 435
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
Allow non-global managers for FlxTween and FlxTimer #1934
Conversation
Omg yes |
Ah, so with |
There's a failing unit test:
|
Oh, right, I can just fix this myself now: https://github.com/blog/2247-improving-collaboration-with-forks :) |
Cool re: collab... |
While this includes a breaking change, it's a fairly small one, and I can't really think of a great way to avoid it. Need a second opinion from @HaxeFlixel/owners though. |
i like this pull request. The only way we can avoid this small breaking change is to leave global manager's name as is, and select different name for "local" manager (but i can't think of another good name for it :) ) |
Thanks a lot for this! We can now finally close that issue. :) Do you think you could incorporate the test code you provided here into the |
Pretty relevant to #1087. Solves the problems of pausing or changing the update speed of states and having their timers and tweens also change. I've been through a few solutions for this, but have eventually landed on this. I have provided a test state to see the new behaviour in action at the bottom.
FlxTween
s andFlxTimer
s now have their own membermanager
, while the existing manager has been renamed toglobalManager
(making this a potentially breaking change where things previously referenced the global managers). Timers and tweens now have an additional optional parameter to set the manager, which defaults to the global manager.In
FlxTween
I moved the implementations oftween
etc to the manager and made the static versions simply defer to these on the global manager. This means thatFlxTween.tween()
still works exactly as it used to, but now we also havemyTweenManager.tween()
.Note that a tweens
manager
is not updated when a tween/timer is added to a manager. I had experimented with having themanager
be the manager that the tween/timer is currently a member of, however it would have become very different in behaviour to the existing use of the global manager. It was complicated because of things such as cancelling and starting/stopping timers/tweens adds and removes them from the manager. If you remove a tween from a manager, you may want to restart it in the same manager, so it would not be desirable to set the manager to null. Therefore the member manager should be treated as "the manager that future changes to this tween will be performed on". This should help with backward compatibility.I had played around with having lazily initialised managers on
FlxBasic
, but ultimately decided that this overcomplicated things, and it is easy enough to add them when needed.Note that this will only break existing games which referenced the global managers as simply
manager
rather thanglobalManager
, but this will be uncommon and easy to solve in those cases.