Game Development Reference
In-Depth Information
Figure 17-13 . Create a new Java class named Treasure.java extends Actor and create Treasure() and update() meth-
ods
Using the Treasure Class: Create Treasure Objects in
the Game
Now that we have a Treasure.java class, we can create Treasure objects for the game.
As you know, this will be done in the InvinciBagel.java class. Declare package protec-
ted (since we're going to reference them outside of InvinciBagel, in Bagel.java) Treas-
ure objects, and name them iTR0 and iTR1 (stands for InvinciBagel Treasure). Add
iT0 and iT1 Image object declarations to the end of your private Image objects com-
pound declaration. Instantiate the iT0 and iT1 Image objects using the Java new
keyword, the Image() constructor method, and the treasure1.png and treasure2.png
image assets, respectively. After that, you can create the iTR0 and iTR1 Treasure ob-
jects, using the Treasure() constructor method, SVG path data of 0,0, 0,64, 64,64 and
64,0 and locations of 50,105 and 533,206 respectively. Make sure that you add these
new Treasure object's spriteFrame ImageView Nodes to the JavaFX Scene Graph, us-
ing the .getChildren().add() method chain, called off of the root Group object. As you
can see in Figure 17-14 , the code is error-free, and we are now ready to test the new
Treasure.java class and the Java code that we have added to the InvinciBagel.java class
to see if we can get Treasure in the game Scene. Your Java code should look like the
following:
 
 
Search WWH ::




Custom Search