Java Reference
In-Depth Information
organized. (By the way, the Illustrator file used to create the assets in this game is included with the
source code, so you can inspect it. The file is saved as a CS3 file.)
On the right of Figure 11-3 we see the Layer tool from Illustrator, which displays each component in
the file. Each of those items will become a JavaFX Node when exported. For example, the item named
jfx:score is the graphic that says “Score: 00000.” This will become a Text node named score in the
JavaFX code and will enable the code to change the displayed text dynamically at runtime. In fact, each
component updated at runtime is given a name with the prefix jfx: , which allows the export tool, in
conjunction with NetBeans, to create a JavaFX class that represents this content. This class will be called
GameAssetsUI . Chapter 1 describes working with the JavaFX Production Suite in more detail.
The game is composed of three screens—the start screen, the welcome screen, and the game screen.
Each of these screens will be an instance of GameAssetsUI . Since each screen does not require all of the
content found in each GameAssetsUI , the game code must prune nodes to create exactly the right
content. For example, neither the start screen nor the game screen require the about panel, just as the
welcome screen and the about screen don't require the text “Game Over,” as this is only used by the
game screen. When each screen is initialized, all unneeded nodes will be removed.
It might make sense to simply create an Illustrator file for each screen, removing the need to delete
unwanted nodes. You could also create one master Illustrator file or a number of smaller Illustrator files
this is a question of workflow. For this game, however, I decided to create a single file because all of the
screens shared a background; I did not want to update three different illustrator files every time I
changed the color of the background. I could have also chosen to create a background Illustrator file and
then three other Illustrator files for each screen. This, of course, would work. But once we get to the code
we will see that initializing each GameAssetsUI for use as three different screens is not all that
complicated. Let me say this: The Illustrator to JavaFX workflow is not perfect. In most cases there will be
JavaFX code that does some sort of initialization on each illustrator file, and I leave it up to you to figure
out what is best for your application and workflow.
There are a few graphics at the bottom of Figure 11-3—five pegs, a flying clown, and a balloon.
These graphics will be placed dynamically on the game screen, so there is no reason to lay them out with
the rest of the graphics. The initialization code of the game screen will handle these graphics specifically,
as they will be at many different locations in the course of a game.
While most of the design was done with Illustrator, some had to happen with JavaFX code. For the
background I wanted searchlights moving back and forth to add to the sense that the action is
happening in a circus tent. Figure 11-4 and Figure 11-5 show the difference between the Illustrator file
and the game in JavaFX.
Search WWH ::

Custom Search