Added a hero to the game who can move around and animates

This commit is contained in:
James Daly
2019-07-18 22:24:56 -04:00
parent 32542df86c
commit c10da7ccf9
7 changed files with 135 additions and 4 deletions

View File

@@ -0,0 +1,35 @@
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)
}
}