09.04.2018 Views

tornadofx-guide

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

9. Shapes and Animation<br />

Interpolators<br />

You can also specify an Interpolator which can add subtle effects to the animation. For<br />

instance, you can specify Interpolator.EASE_BOTH to accelerate and decelerate the value<br />

change at the beginning and end of the animation gracefully.<br />

val rectangle = rectangle(width = 60.0, height = 40.0) {<br />

}<br />

padding = Insets(20.0)<br />

timeline {<br />

keyframe(5.seconds) {<br />

keyvalue(rectangle.rotateProperty(), 180.0, interpolator = Interpolator.EASE_B<br />

OTH)<br />

}<br />

}<br />

Cycles and AutoReverse<br />

You can modify other attributes of the timeline() such as cycleCount and autoReverse .<br />

The cycleCount will repeat the animation a specified number of times, and setting the<br />

isAutoReverse to true will cause it to revert back with each cycle.<br />

timeline {<br />

keyframe(5.seconds) {<br />

keyvalue(rectangle.rotateProperty(), 180.0, interpolator = Interpolator.EASE_B<br />

OTH)<br />

}<br />

isAutoReverse = true<br />

cycleCount = 3<br />

}<br />

To repeat the animation indefinitely, set the cycleCount to Timeline.INDEFINITE .<br />

Shorthand Animation<br />

142

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!