Open Tal3D opened 10 years ago
That's a nice addition. Any reason to avoid an update()
method, @IQAndreas ?
FlxTween? Does flixel-community have tweening?
To have it work natively with flixel's update loop it might be better to have it extend FlxBasic (just another thought).
FlxTween? Does flixel-community have tweening?
https://github.com/FlixelCommunity/flixel/pull/114#issuecomment-9841241
Any reason to avoid an
update()
method, @IQAndreas ?
I thought I had a good reason for it. The only thing I remember thinking was that for performance (and synchronization) reasons it may be a bad idea for each instance to have its own "ticker", but we should instead use the "global Flixel time" in some way. If we add it to the list of items that Flixel updates each frame, it would be perfect.
Looking at the way the FlxTween
class is currently being used in FlxSound
, the progress is updated each frame anyway.
Keep in mind though, you cannot increment with ++
with each call to update, you need (provided it updates each "Flixel Frame"):
public function update():void
{
this.progress += FlxG.elapsed;
}
I would also recommend adding an autoUpdate
flag to the constructor in case users want to manually control the progress based on something other than time. As an example, I considered using FlxTween
to control sound panning based on an object's location between the left and right side of the screen.
To have it work natively with flixels update loop it might be better to have it extend FlxBasic.
Although, FlxBasic
contains many extra properties and values that are unnecessary for just a simple Tween instance.
Also, I would like Tweens to be updated before any classes that use the tween values get their update()
method called (perhaps at or before the preUpdate()
stage would be best). That way, all places that use the tween get the exact same value
each frame.
I don't see a problem in just adding a separate loop in FlxGame
that updates all tweens before updating all FlxBasic
instances.
In HaxeFlixel, we have a TweenManager
plugin that updates all the tweens each frame. I think that's a solid approach, also makes it consistent with the TimerManager
.
Tweens themselves are created via static methods like FlxTween.tween()
and automatically added to the manager, making them very convenient to use.
In HaxeFlixel, we have a
TweenManager
plugin that updates all the tweens each frame. I think that's a solid approach, also makes it consistent with theTimerManager
.
That would work! :) And that way only one item has the overhead of extending FlxBasic
, and ticking every frame.
Then we would need a function to add FlxTweens to the manager though.
I think update()
and progress
can live together. It's up to the developer to decide what to do. E.g. if I just want to "step" the tween and I don't care how it will be done, a call to update()
will do the trick. If I want a fine control over the increment, I can manipulate progress
directly.
I like the idea of a TweenManager as @Gama11 suggested, but I don't like the idea of tweens being automatically added. IMHO the less automatic things we have, the easier to understand what is going on.
My idea:
// I want total control
var t :FlxTween = new FlxTween();
while(myStuff()) {
t.update();
}
// or I want Flixel to take care of it for me
FlxG.tweens.add(t);
// later...
FlxG.tweens.remove(t);
While I agree on tweens not being added automatically to the manager I believe they should be removed by the manager automatically once they are finished as it would be redundant to increment the progress over 100% when it will be set back inside the tween to 100% automatically.
In FlxTween you have to increment the tween progress yourself. Why not have an update() function do this? Seems like the most intuitive way of doing it. Plus it works nice with flixel.