35 lines
820 B
Scala
35 lines
820 B
Scala
package fmon.draw
|
|
|
|
import scalafx.scene.image.ImageView
|
|
|
|
import scalafx.Includes._
|
|
import scalafx.animation.Transition
|
|
import scalafx.util.Duration
|
|
|
|
class AnimatedImageView extends ImageView {
|
|
def this(img: Drawable, dur: Duration) {
|
|
this()
|
|
animate(img, dur)
|
|
}
|
|
|
|
var drawable: Drawable = _
|
|
var duration: Duration = _
|
|
|
|
private var animation: SpriteAnimation = _
|
|
|
|
def animate(img: Drawable, dur: Duration) {
|
|
drawable = img
|
|
duration = dur
|
|
animation = new SpriteAnimation(this, drawable, duration)
|
|
animation.cycleCount = Transition.Indefinite
|
|
animation.play()
|
|
}
|
|
|
|
def pause(): Unit = animation.pause()
|
|
def play(): Unit = animation.play()
|
|
def playFromStart(): Unit = animation.playFromStart()
|
|
def stop(): Unit = {
|
|
animation.stop()
|
|
animation.interpolate(0)
|
|
}
|
|
} |