scalafx.animation.Timeline未能按预期工作 [英] scalafx.animation.Timeline not working as expected

查看:159
本文介绍了scalafx.animation.Timeline未能按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天前,我开始尝试使用ScalaFX API.要了解此API的用法,请查看 GitHub .为了测试TimeLine类的功能,我使用了以下示例:

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.

在示例中,用于定义TimeLine对象的代码如下:

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

也找不到值autoReversekeyFramess. 我没有亲自设置项目及其结构,而是从GitHub克隆了一个"Hello world"项目: scalafx-hello-world .该项目并正确编译.

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.

这可能是ScalaFX中的错误吗?您有解决该问题的想法吗?

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

完整代码

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

推荐答案

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

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

val timeline = new Timeline { 
   ... 
}

这篇关于scalafx.animation.Timeline未能按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆