scalafx.animation.Timeline无法按预期工作

时间:2015-02-20 13:47:03

标签: scala scalafx

我几天前就开始试用ScalaFX API了。要了解此API的用法,我正在查看GitHub上的示例。为了测试我使用此示例的TimeLine类的功能:ScalaFXAnimation

定义TimeLine对象的代码在示例中如下所示:

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}
  )
}

如果我尝试在我自己的项目中执行此操作,我会收到一些编译错误,例如:

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

也找不到值autoReversekeyFramess。 我没有自己设置项目及其结构,而是从GitHub克隆了一个“Hello world”项目:scalafx-hello-world。这个项目编译得当。

它可能是ScalaFX中的错误吗?你对如何解决这个问题有任何想法吗?

EDIT2:完整代码

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 个答案:

答案 0 :(得分:2)

在最新版本中,您在new前面缺少Timeline。它应该是:

val timeline = new Timeline { 
   ... 
}
相关问题