Game Development Reference
In-Depth Information
Figure 11-7 . Create a private void addGameActorNodes() method; .add() iBagel.spriteFrame ImageView to root ob-
ject
It is important to note that I am calling this .addGameActorNodes() method, at the
top of the InvinciBagel class, inside of the .start() method, before I call the .ad-
dNodesToStackPane() method. There is a very good reason for doing this, and it goes
back to what you learned about JavaFX in Chapter 4 . Remember the objects that you
add to the StackPane layer management object are displayed using a Z-index (or Z-or-
der ), which means that they are “ stacked ” on top of each other. If any of these layers
do not have an alpha channel , which we learned about in Chapter 5 , then nothing be-
hind them will be able to show through! For this reason, the easiest way to get our
Splashscreen to overlay our game at any point in time that a player clicks the
INSTRUCTIONS Button control object is to add these assets last.
By having your .addNodesToStackPane() method called after your .addGameAct-
orNodes() method, you will guarantee that your game assets will always be at a lower
Z-index than your Splashscreen assets. This means that the SplashScreenBackplate
and the SplashScreenTextArea ImageView “plates” will always be at the top Z-index
layers in the StackPane, and thus, when these are displayed (made visible), they will
completely cover your game play. This is because the SplashScreenBackplate
ImageView contains an opaque PNG24 image asset that is the same size as your Scene
(and Stage) object.
We will be seeing the result of this method order reorganization later on when we
test the new InvinciBagel game application, and you will see that we have resolved this
problem of the game actor(s) displaying on top of the Splashscreen. We accomplished
this simply by changing the order that your programming code is executed in. This
should also point out to you that the order that the Java programming code is executed
in is almost as important as the Java programming logic itself!
Creating and Managing Your Cast: .createCastingDir-
ection()
Now the time has come to implement the other class that we created in Chapter 10 , the
CastingDirector.java class, and its CastingDirector() constructor method. We will do
this inside of another new custom method we will create called .createCastingDirec-
tion() . This method will contain the initial instantiation of a CastingDirector object
named castDirector, which we will create by using the Java new keyword and the Cast-
ingDirector() constructor method, as well as adding the iBagel Actor object to the
Search WWH ::




Custom Search