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 Enhancement #204

Open
Tal3D opened this issue Apr 30, 2014 · 11 comments
Open

FlxTween Enhancement #204

Tal3D opened this issue Apr 30, 2014 · 11 comments

Comments

@Tal3D
Copy link

Tal3D commented Apr 30, 2014

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
Copy link
Member

Dovyski commented Apr 30, 2014

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

@Gama11
Copy link

Gama11 commented Apr 30, 2014

FlxTween? Does flixel-community have tweening?

@Dovyski
Copy link
Member

Dovyski commented Apr 30, 2014

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

@Tal3D
Copy link
Author

Tal3D commented Apr 30, 2014

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

@IQAndreas
Copy link
Member

FlxTween? Does flixel-community have tweening?

#114 (comment)

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
Copy link
Member

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
Copy link

Gama11 commented Apr 30, 2014

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 IQAndreas added this to the Future release milestone May 1, 2014
@IQAndreas
Copy link
Member

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
Copy link
Author

Tal3D commented May 1, 2014

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

@Dovyski
Copy link
Member

Dovyski commented May 2, 2014

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
Copy link
Author

Tal3D commented May 2, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants