scalafx.animation.Timeline not working as expected

心不动则不痛 提交于 2019-12-13 02:27:50

问题


I've started to try out the ScalaFX API few days ago. To learn the usage of this API I'm looking at the examples on GitHub. For testing out the features of the TimeLine class I used this example: ScalaFXAnimation.

The code to define a TimeLine object is looking like this in the example:

val timeline = new Timeline {
  cycleCount = Timeline.Indefinite
  autoReverse = true
  keyFrames = Seq(
    at (2 s) {rect1.x -> 200d tween Interpolator.EASE_IN},
    at (4 s) {rect1.x -> 300d},
    at (3 s) {rect2.y -> 100d tween Interpolator.EASE_BOTH},
    at (4 s) {rect2.y -> 300d},
    at (4 s) {rect2.width -> 300d tween Interpolator.EASE_OUT}
  )
}

If I try to do this in my own project I recieve some compile errors like:

Error:(58, 5) not found: value cycleCount

The values autoReverse, keyFrames and s are also not found. I did not set up the project and its structure by myself but cloned an "Hello world"-project from GitHub: scalafx-hello-world. This project and compiled properly.

Could it be a bug in ScalaFX? Do you have any ideas how to solve this problem?

EDIT2: Complete Code

package hello

import scalafx.animation.{Timeline, Interpolator}
import scalafx.application.JFXApp
import scalafx.application.JFXApp.PrimaryStage
import scalafx.scene.Scene
import scalafx.scene.paint.Color
import scalafx.scene.shape.Rectangle
import scalafx.Includes._
import scala.language.postfixOps

object ScalaFXHelloWorld extends JFXApp {

  val rect1 = new Rectangle {
    width = 100
    height = 200
    fill = Color.Red
  }

  val rect2 = new Rectangle {
    width = 200
    height = 120
    fill = Color.Green
  }

  val timeline = Timeline {
    cycleCount = Timeline.Indefinite
    autoReverse = true
    keyFrames = Seq(
      at (2 s) {rect1.x -> 200d tween Interpolator.EASE_IN},
      at (4 s) {rect1.x -> 300d},
      at (3 s) {rect2.y -> 100d tween Interpolator.EASE_BOTH},
      at (4 s) {rect2.y -> 300d},
      at (4 s) {rect2.width -> 300d tween Interpolator.EASE_OUT}
    )
  }

  timeline.play()
  stage = new PrimaryStage {
    scene = new Scene {
      content = List(rect1, rect2)
    }
  }
}

回答1:


In the latest version you are missing new in front of Timeline. It should be:

val timeline = new Timeline { 
   ... 
}


来源:https://stackoverflow.com/questions/28630476/scalafx-animation-timeline-not-working-as-expected

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!