Note: This post has been superseded by the Radar Love: JavaFX Animation Examples by Sven post, so please visit that page.
Sven Drieling, whose code examples have been featured previous posts, has some examples on PlanetJFX of animating and interacting with a rectangle. There are four examples:
- The first example (RectMove.fx) is very much like the Red Rubber Ball solution in an earlier post, so you'll be in familiar territory at this point.
- The second example (RectResize.fx) is an example in which you can resize a rectangle by dragging the lower left corner.
- The third example (RectBounce.fx) animates a rectangle by making it bounce off the sides of a Canvas. It uses the JavaFX dur operator to control the rate of movement.
- The fourth example (RectCatch.fx) uses the onMousePressed event to enable the user to "catch" the rectangle as it is bouncing around.
These examples begin to demonstrate, among other things, how you can create animated games in JavaFX Script. Take a look at the code, and paste them into JavaFXPad. You might want to run the JavaFX Canvas Tutorial program discussed in this post to refresh yourself on the Canvas/2D related techniques used in Sven's examples.
By the way, I just found out that I'll be presenting in two JavaFX sessions (a university session, and a conference presentation) at JavaPolis 2007 on December 10 - 14, in Antwerp, Belgium. If you are in attendance, please introduce yourself as I'd like to meet you!