scalafx.animation.Timeline 未按预期工作
scalafx.animation.Timeline not working as expected
几天前我开始试用 ScalaFX API。要了解此 API 的用法,我正在查看 GitHub. For testing out the features of the TimeLine
class I used this example: 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
也找不到值 autoReverse
、keyFrames
和 s
。
我没有自己设置项目及其结构,而是从 GitHub: scalafx-hello-world 克隆了一个 "Hello world"-project。此项目并正确编译。
这可能是 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)
}
}
}
在最新版本中,Timeline
前面缺少 new
。应该是:
val timeline = new Timeline {
...
}
几天前我开始试用 ScalaFX API。要了解此 API 的用法,我正在查看 GitHub. For testing out the features of the TimeLine
class I used this example: 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
也找不到值 autoReverse
、keyFrames
和 s
。
我没有自己设置项目及其结构,而是从 GitHub: scalafx-hello-world 克隆了一个 "Hello world"-project。此项目并正确编译。
这可能是 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)
}
}
}
在最新版本中,Timeline
前面缺少 new
。应该是:
val timeline = new Timeline {
...
}