terça-feira, 17 de janeiro de 2017

Have fun creating JavaFX 2d games

After the pong game, today I had a good time creating another small JavaFX game. This time, a little more playable game.

I think JavaFX is the best plataform to create games nowadays. No external dependency is required to create a playable and rich game. To the game which code you can see below, I spent about 3 hours and I could continue adding features to it, but I just wanted to do something else.

But why JavaFX is so great about creating games?

  • Hardware acceleration  for rendering of graphics comes by default;
  • It is available on Oracle Java JDK and also with OpenJFX project (no additional dependencies);
  • It has a canvas that is equivalent to the HTML 5 canvas;
  • It can play sound, video and has Java networking by default and a lot of Java platform benefits
  • You can port JavaFX to a mobile using Gluon / JavaFX Ports (in fact, I did this already and I still have the stacker game running on my mobile);
  • It has 3d capabilities;
  • You can port the game to the web using jpro.
You can find the AircraftWar game source code in my github and to run it just use:

javac AircraftWar.java


java AircraftWar

segunda-feira, 16 de janeiro de 2017

Pong Game in JavaFX using 90 lines of code

A pong game implementation using 90 lines of Java code only. It is possible to write with less lines, but it would make the code unreadable.

To run it:

* Download the source and save it to a file called Pong.java
* Using JDK 8, run: javac Pong.java  and then java Pong

You can improve the game mainly by changing its AI - now basically the enemy follows the ball. See the code below.

quinta-feira, 12 de janeiro de 2017

Some visual effects and data visualization apps using JavaFX

In this post I am going to show some visual effects I have created with JavaFX which I have posted in my portuguese JavaFX blog.

We see cool visual effects in JavaFX since its 1.x version. For example, I have this great book from Lucas Jordan:

In this book Lucas Jordan explore known Graphics Computer algorithms using JavaFX Script. I missed a book like that for JavaFX 8 and the reason is that it is really fun to create visual effects... Fortunately I have seem Daniel Shiffman creating a lot of cool apps almost weekly!

In my last post I talked about a class that help us to quickly create visual effects with JavaFX. Since then, I created a few, and in this post I will share it with you.

The big Red Ball

This is a quick sample showing how to write pixel by pixel of a canvas.


Create super shapes using JavaFX


The algorithm to create it was based on Daniel Shiffman implementation.


The metaballs effect using JavaFX. You can see the video I recorded (audio in Portuguese) and also check shiffman's video about this topic.

Escape the Maze

I talked about this app on my last post.

Open Data visualization 

I plan to make a specific topic about this app, but for now you can see the vide below. It is an application that access a REST API to help users to better visualize open data. I personally liked it and I think it is very useful. I also used JSONB on this App! See the video below for more information.


JavaFX was and continues to be awesome. It is already easy, but with DrawingFX it is even easier! See my github for all code and feel free to contribute to DrawingFX

quarta-feira, 11 de janeiro de 2017

Escape the JavaFX maze using Genetic Algorithms

In Genetic Algorithms with Java post I presented a "escape the maze" example. In this post, I will share with you a JavaFX application used to control the genetic algorithm execution and visualize the directions after running the evolution.

The JavaFX application can generate mazes with the number of blocks (walls), columns and rows you select. You can also change the evolution parameters, such as the population, the genes multiplier (it resolves to columns * rows * genes multiplier and it determines the number of genes - directions or steps) and you can also choose the number the generations before evolving. To be honest, I spent hours playing with it and you can play with it as well! You just need Java and Maven:
$ mvn clean package exec:java -Dexec.mainClass=org.fxapps.genetics.mazefx.MazeFXApp

See it in action: