Game Development Reference
In-Depth Information
Figure 16-41
.
Optimizing the interaction between the collide() method and the checkCollision() method
Use the
Run Project
work process to make sure the code works as it did before
the method optimizations.
Optimizing the Scene Graph: Using the
Group Class
Since we're not really using the StackPane for image layer compositing or UI design,
other than the splashscreen use, let's add another optimization, and use a
Group
class
(object) for our game, since it is further up the class hierarchy, and closer to the Node
superclass than the more specialized StackPane class (object) is. Rather than using a
class that uses the more complex
Object Node Parent Region Pane
StackPane
hierarchy, we will use the much shorter and simpler
Object Node
Parent Group
hierarchy. The significance of this optimization is that using a
Group root Node uses a lot less code (properties and methods) in system memory.
Since we are not specifically using any of the highly specialized StackPane properties
or methods, we can perform a major optimization by using a Group class. A Group ob-
ject (class) uses
fixed
object positioning, so we will have to redo the code for our
HBox
and Actor objects, but only after we use the
Run Project
work process to
see exactly how using a Group differs from using a StackPane. After all, it's all about