Game Development Reference
In-Depth Information
CHAPTER 12
Setting Boundaries for Your Ac-
tion Figure in 2D: Using the
Node Class LocalToParent At-
tribute
Now that we have organized your Java code into logical methods in the InvinciBa-
gel.java class, and wired up the GamePlayLoop .handle() method to the Bagel .update()
method in
Chapter 10
, to make sure that our KeyEvent handlers will move our Invin-
ciBagel character around the screen, it is time to establish some
boundaries
for our
game hero, so that he does not leave the field of play, so to speak. To do this, we will
need to dive into the JavaFX
Node
superclass at a much deeper level of detail then we
how they function
relative
to the Parent Node, which is located above them in the Scene
Graph. For our Actor ImageView Node(s), that Parent Node would be the Scene Graph
root
StackPane Node.
Before we start getting into code complexities such as absolute or relative transform-
ation, which we will be looking at during this chapter, and things such as collision detec-
tion and physics simulation, which we will cover later in
Chapters 16
and
17
,
we will
need to get back into our
InvinciBagel.java
primary application class Java code here in
Chapter 12
,
so that we can do a few more things that will optimize the Java 8 foundation
for our game. We have been putting our game engines into place during the first part of
this topic, and I want to make sure that everything is “up to snuff” before I start to build
complex code structures on top of what we have put into place so far. We're going to
make sure everything is “locked down tightly!”