HaxeFlixel / flixel

Free, cross-platform 2D game engine powered by Haxe and OpenFL
https://haxeflixel.com/
MIT License
1.96k stars 433 forks source link

Add better "tween chaining" option #1064

Closed Beeblerox closed 8 years ago

Beeblerox commented 10 years ago

it can be done only with tween onComplete() now, which isn't very good

Gama11 commented 10 years ago

How would this look like?

Beeblerox commented 10 years ago

haven't decided yet. this issue is just a note, since it has been discussed on Skype conference

JoeCreates commented 10 years ago

What current options have you considered? Here's a couple:

FlxTween.chain([FlxTween.tween(blah), FlxTween.tween(blah), FlxTween.tween(blah)])

Or perhaps (returning an array of tweens): FlxTween.tween(blah).thenTween(blah).thenTween(blah);

Gama11 commented 10 years ago

Return an array of tweens?

JoeCreates commented 10 years ago

@Gama11 FlxTween.tween() lets you keep a reference to the tween. This would not be possible with the second structure as there is no single tween to return. It is easy enough to have thenTween() pass an array to each next tween such that thenTween() can return an array of all the tweens in the chain. This is just so the user has some way to keep a reference to the tween objects should they need it.

Gama11 commented 10 years ago

I see, makes sense.

I think I like the first option better.

Tiago-Ling commented 10 years ago

+1 for chaining like this:

FlxTween.tween().tween().onComplete().tween();

JoeCreates commented 10 years ago

The first way is more standard, the second way is a little less cumbersome to type, but is also a lot more flexible.

I prefer the second chaining way. As @Tiago-Ling pointed out, you can also having things like .onComplete() using this syntax, also reducing the brace complexity. Other options include things like adding simultaneous tweens.

Perhaps, rather than returning an array of tweens, it would be better to have a FlxTweenGroup or FlxTweenChain, which can be stopped, canceled, and looped in the same way a single tween can.

In fact, this syntax could potentially completely replace the existing tweenoptions object, which is a pain with autocomplete, and generally looks ugly.

Delays could be done as such:

FlxTween.delay(2).tween(blah).delay(2).tween(blah).onComplete(blah).loopAll();

I also threw in a potential way to make the whole sequence loop. xD Look at the control you could have. :) Note that this would also be possible with the other tween methods.

MSGhero commented 10 years ago

Tweenlite lib uses a TimeLine(Lite) to manage tweens, an internal one to manage tweens in general and then you can make your own for more control. First image is a big timeline. That would solve the array of tweens thing, though it's kinda major to add in.

IBwWG commented 8 years ago

I'm not sure that the features added allow you to loop the chain as a whole, is that right?

Gama11 commented 8 years ago

Yeah, I don't think that's possible right now.