Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 12 ■ 3D MoDel Design anD priMitives: Using JavaFX 9 shape3D Classes

This can be easily accomplished by modifying your current gameBoard.getChildren().add(sphere);
Java statement to instead be gameBoard.getChildren().addAll(sphere, box);, as shown here and in
Figure 12-3:


box = new Box(100, 100, 100); // in .createBoardGameNodes() method
gameBoard.getChildren().addAll(sphere, box); // in .addNodesToSceneGraph() method


After declaring the Box object, instantiate the object inside of your createBoardGameNodes() method
using the same 100 units value that you used for the Sphere. You will be able to see how the sizes relate to
each other since they will both be created at 0,0,0. For the Box constructor method, this takes three (double)
values, which should all be 100.
Next, declare a Cylinder named pole at the top of your class, and instantiate it inside of the
.createBoardGameNodes() method, using a width of 50, a height of 250 and 24 for the number of sections
or divisions used for the mesh (LINE) draw representation.
This should all look like the following Java code, which is shown highlighted in yellow and blue in
Figure 12-4:


Cylinder pole; // Declare object for use at the top of your class
...
pole = new Cylinder(50, 250, 24); // in .createBoardGameNodes() method


Figure 12-3. Use the .addAll() method to add a box object to the SceneGraph in the addNodesToSceneGraph()
method

Free download pdf