FlixelCommunity / flixel

Community fork of Adam “Atomic” Saltsman's popular game engine Flixel. Distilled from a variety of Flash games he worked on over the last couple years, including Gravity Hook, Fathom and Canabalt, its primary function is to provide some useful base classes that you can extend to make your own game objects.
http://flixelcommunity.org/
Other
84 stars 17 forks source link

FlxTween Enhancement #204

Open Tal3D opened 10 years ago

Tal3D commented 10 years ago

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.

public function update():void
{
    progress++;
}
Dovyski commented 10 years ago

That's a nice addition. Any reason to avoid an update() method, @IQAndreas ?

Gama11 commented 10 years ago

FlxTween? Does flixel-community have tweening?

Dovyski commented 10 years ago

Yeah, a very simple class was added to handle some dirty work.

Tal3D commented 10 years ago

To have it work natively with flixel's update loop it might be better to have it extend FlxBasic (just another thought).

IQAndreas commented 10 years ago

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.

IQAndreas commented 10 years ago

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.

Gama11 commented 10 years ago

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.

IQAndreas commented 10 years ago

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.

That would work! :) And that way only one item has the overhead of extending FlxBasic, and ticking every frame.

Tal3D commented 10 years ago

Then we would need a function to add FlxTweens to the manager though.

Dovyski commented 10 years ago

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);
Tal3D commented 10 years ago

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.