diff --git a/FakeMon/src/fmon/draw/AnimatedImage.scala b/FakeMon/src/fmon/draw/AnimatedImage.scala index 2b5627e..4360e8f 100644 --- a/FakeMon/src/fmon/draw/AnimatedImage.scala +++ b/FakeMon/src/fmon/draw/AnimatedImage.scala @@ -10,6 +10,7 @@ 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) diff --git a/FakeMon/src/fmon/draw/CharSet.scala b/FakeMon/src/fmon/draw/CharSet.scala new file mode 100644 index 0000000..4a745d2 --- /dev/null +++ b/FakeMon/src/fmon/draw/CharSet.scala @@ -0,0 +1,52 @@ +package fmon.draw + +import java.io._ + +object CharSet { + final val FramesPerPose = 3 + final val Poses = IndexedSeq("South", "West", "East", "North") + final val NumAcross = 4 + final val NumDown = 2 + + def apply(file: File, index: Int): Sprite = { + val na = NumAcross * FramesPerPose + val nd = NumDown * Poses.size + val palette = new Palette(new FileInputStream(file), na, nd) + val x = index % NumAcross + val y = index / NumAcross + val xx = x * NumAcross + def pose(i: Int): AnimatedImage = { + val yy = y * NumDown + i + val images = IndexedSeq(palette(xx, yy), palette(xx - 1, yy), palette(xx, yy), palette(xx + 1, yy)) + new AnimatedImage(images) + } + val poses = Poses.zipWithIndex.map{case (p, i) => (p, pose(i))}.toMap + new Sprite("South", poses) + } +} + +import scalafx.application.JFXApp +import scalafx.scene._ +import scalafx.scene.control._ +import scalafx.scene.image._ +import scalafx.scene.paint.Color._ +import scalafx.util.Duration + +object CharSetDemo extends JFXApp { + val view = new ImageView + stage = new JFXApp.PrimaryStage { + title.value = "Hello Stage" + width = 600 + height = 450 + scene = new Scene { + fill = LightGreen + content = view + } + } + val filename = raw"C:\Users\dalyj\Documents\Design\Images\CharSets\remakertp01.png" + val walker = CharSet(new File(filename), 1) + val animation = new SpriteAnimation(view, walker, new Duration(600)) { + setCycleCount(scalafx.animation.Transition.Indefinite) + } + animation.play() +} \ No newline at end of file diff --git a/FakeMon/src/fmon/util/YamlHelper.scala b/FakeMon/src/fmon/util/YamlHelper.scala index 4d11f81..91bf8d5 100644 --- a/FakeMon/src/fmon/util/YamlHelper.scala +++ b/FakeMon/src/fmon/util/YamlHelper.scala @@ -86,6 +86,10 @@ object YamlHelper { mapper.readValue[Map[String, T]](source) } + def write[T](source: OutputStream, item: T) = { + mapper.writeValue(source, item) + } + def writeMap[T](source: OutputStream, items: Map[String, T])(implicit m: Manifest[T]) = { mapper.writeValue(source, items) }