Added a hero to the game who can move around and animates
This commit is contained in:
35
FakeMon/src/fmon/draw/AnimatedImageView.scala
Normal file
35
FakeMon/src/fmon/draw/AnimatedImageView.scala
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user