円を左右に動かすアニメーション
JRubyFXでアニメーションをやりたくて、まずは簡単なところから始めてみた。
はじめに、サークルを描画して、大きさを150、色をgreen、位置を縦方向に200の場所においた。
そのあと、play関数を呼んで、
そこで、idが"c"となっているサークルのX方向をtimelineを使って動かす。
0秒(0.sec)の状態で横方向200の位置、1秒(1.sec)の状態で横方向600の位置、自動的にリバースさせる
という設定になっている。
timelineの設定はnodeごとにできるっぽい。
require 'jrubyfx' class Hello < JRubyFX::Application def start(stage) @stage = stage with(stage,title: "sample",width: 800,height: 400) do layout_scene do group do c = circle(150, Color.web("green"), id: "c") c.translate_y = 200 end end show end play end def play translate_x = @stage['#c'].translateXProperty timeline(cycle_count: :indefinite, auto_reverse: true) do animate translate_x, 0.sec => 1.sec, 200 => 600 end.play end end Hello.launch
なるほど、なんとなくアニメーションがわかってきたぞ。