27 lines
717 B
Scala
27 lines
717 B
Scala
package fmon.draw
|
|
|
|
import javafx.animation.{Transition => JTransition}
|
|
|
|
import scalafx.Includes._
|
|
import scalafx.animation._
|
|
import scalafx.scene.image.ImageView
|
|
import scalafx.util.Duration
|
|
|
|
class SpriteAnimation(val view: ImageView, val image: Drawable, val duration: Duration) extends JTransition {
|
|
setCycleDuration(duration)
|
|
setInterpolator(Interpolator.Linear)
|
|
setAutoReverse(false)
|
|
|
|
def interpolate(t: Double): Unit = {
|
|
image.draw(view, t)
|
|
}
|
|
}
|
|
|
|
class AnimatedImage(val frames: IndexedSeq[Drawable]) extends Drawable {
|
|
val lastIndex = -1
|
|
|
|
def draw(view: ImageView, t: Double): Unit = {
|
|
val index = Math.min((frames.size * t).toInt, frames.size - 1)
|
|
frames(index).draw(view, t)
|
|
}
|
|
} |