Experimental macro-based tweening library. Inspired mostly by Slide and Ceramic Engine's integrated tweening system.
import twny.TwnyTools.tween;
class Example {
var s = { x: 0., y: 0., scale: { x: 0., y: 0.} };
static function main() {
tween(0)
.then(
tween(1)
.to(Circ.easeInOut, {
s.scale.x = 2;
s.scale.y = .5;
})
.to(Linear.easeNone, {
s.x += 200;
})
.onComplete(() -> {
trace('x: ${s.x}');
})
)
.then(
tween(.5)
.to(Circ.easeOut, s.y -= 100)
.then(
tween(.5)
.to(Circ.easeIn, s.y += 100)
)
)
.start()
.repeat();
twny.TwnyTools.update(1); // x: 200
twny.TwnyTools.update(1); // x: 400
}
}
- Nice property syntax with access to nested fields at any depth! (also see also about autocompletion)
tween(1.0)
.to(Quad.easeIn, {
spr.pos.x = 100;
scene.getChildAt(1).pos.y = 100;
})
- Tween chaining and branching!
tween(0) // 1st tween just to combine a few tweens below (can be also used for delay)
.then(
tween(1.0).to(...) // will be started after 1st tween
)
.then(
tween(3.0).to(...) // will be started after 1st tween in parallel with tween above
.then(...)
.then(...)
)
- Repeating the whole tween tree without using oncomplete callback!
tween(1).to(Quad.easeIn, spr.x = 100)
.then(
tween(1).to(Quad.easeIn, spr.x = 200)
)
.repeat()
.start();
TwnyTools.update(1); // spr.x == 100
TwnyTools.update(1); // spr.x == 200
TwnyTools.update(1); // spr.x == 100
TwnyTools.update(1); // spr.x == 200
- Parallel transitions with different easings! (not a big deal, but that's what made me start working on own tween lib)
tween(1.0)
.to(Quad.easeIn, spr.x = 100)
.to(Circ.easeOut, spr.y = 50)
- Time callbacks and playback control!
var t = tween(1.0)
.onStart(() -> trace('Start!'))
.on(.5, () -> trace('Half!'))
.onComplete(() -> trace('The end!'))
.start();
t.pause();
t.resume();
- Macro-based, no reflection (but a several macro-generated anonymous functions instead)
-D twny-autocompletion-hack
- workaround to achieve autocompletion in properties. See issues:
HaxeFoundation/haxe#7699
HaxeFoundation/haxe#9421