Thursday, January 10, 2013

2D Water Effects with JavaFX and Scala

Join me on my way to a simple water effect using JavaFX and Scala like shown below.

Only recently I've discovered a very nice blog about game tutorials, in particular an article about a 2D water effect got my attention. It amazed me that you only need such simple arithmetic to get such a nice effect. You can read about the basic math at the original article,  see below for my first shot at an implementation in JavaFX.

It is nice to see how much work JavaFX does behind the scenes - you just have to make sure your polygon has the right coordinate list, all the stuff needed for painting is done behind the scenes. By using a simple gradient the water looks nice, too.


I've pushed the whole project setup to github.

You may notice a small glitch at the beginning of the animation. Some minutes ago I've installed OpenJDK8 early access and started the application without recompiling, and it went away. Why buy new hardware? Just install new VMs ;-)