Java Reference
In-Depth Information
This code shows that the strategy is to create a Phys2D
World
and then mirror the
Bodies
in that
World
with JavaFX
Nodes
. In order to mirror the
Bodies,
a new class called
WorldNode
is created—a
simple JavaFX class that contains two sequences and an abstract function called
update
. In this way, a
Node
will be created that extends
WorldNode
so that each
Node
in the
Scene
maintains a reference to its
corresponding
Bodies
in the
World
. Looking at the variables in the code, we can see that
worldNodes
maintains a reference to all
WorldNodes
in the application,
world
is a Phys2D
World
and maintains a
reference to the
bodies
in each
WorldNode,
and
group
contains all
WorldNodes
in the scene. The function
addWorldNode
shows these relationships, as this method is how content is added to the application. Note
that there is a reference to something called a
Joint
in the code, which will be described in a later
example.
The function
simpleBalls
shows how
addWorldNode
is called, which produces a scene like the one in
Figure 6-1.
Figure 6-1.
One falling ball