Starling-Framework icon indicating copy to clipboard operation
Starling-Framework copied to clipboard

Tween API improvements

Open elsassph opened this issue 14 years ago • 4 comments

Tween methods currently all return void and require to write lots of code for simple things.

That's a big missed opportunity to allow chaining for cheap by just returning the tween instance, so your Tween example could look like:

new Tween(object, 2.0, Transitions.EASE_IN_OUT) .animate("x", object.x + 50) .animate("rotation", deg2rad(45)) .fadeTo(0) // equivalent to 'animate("alpha", 0)' .run(); // equivalent to Starling.juggler.add(tween);

Add a static helper and you have an all modern API: Tween.select(object, 2.0, Transitions.EASE_IN_OUT).fadeTo(1).run();

elsassph avatar Dec 07 '11 10:12 elsassph

Ha, Philippe, that's a great idea! Indeed, that would make it easy to initiate tweens in a very elegant way. Perfect! Thanks for the suggestion -- that's what I call constructive feedback! =)

I'll add that to Starling soon.

Daniel

PrimaryFeather avatar Dec 07 '11 11:12 PrimaryFeather

Also .onComplete/.onCompleteArgs could be gathered as a chainable .complete(handler, args) ;)

elsassph avatar Dec 08 '11 09:12 elsassph

Building on the shortcut methods like fadeTo that return this instance, another suggestion is the ability to chain separate Tweens would be to add a then() function:

then(duration:Number, delay:Number=0, transition:String=""):Tween

then() returns a new Tween object that will get run after this Tween Object's completion (plus an optional delay). So you can quickly chain multiple Tweens in a row:

obj.scaleX = obj.scaleY = obj.alpha = 0;
new Tween(obj, 0.5).fadeTo(1).scale(1).then(0.5, 0.25).scale(2).then(0.5, 0.25).fadeTo(0).scale(0).run();

Which, in english, means "grow and fade in for the first 500ms, then pause 250 ms, then grow to 2x, then pause 250ms, then fade out the last 500 ms"

The run() call would need to be marshaled to the front of the Tween stack, but that should be easy enough.

Of course, it's easy enough to extend Tween to do exactly this, or maybe I'll submit a pull request. =)

jcward avatar Dec 06 '12 18:12 jcward

If the API is equal to the TweenJS (http://www.createjs.com/#!/TweenJS), we can use the export of toolkit for CreateJS (http://www.adobe.com/br/products/flash/flash-to-html5.html). This can be a plugin for starling.

renanvaz avatar Aug 25 '13 05:08 renanvaz