Game Development Reference
In-Depth Information
Next, let's take a look at how we add our newly created iBagel object into our
game's Scene Graph object, which is currently a Stackpane object named root.
Adding Your iBagel to the Scene Graph: .ad-
dGameActorNodes()
One of the steps that JavaFX application developers often forget is to add their objects
that will need to be displayed in the Scene (and on the Stage that the Scene object is at-
tached to) to the root object of the Scene Graph. In our case, this is a StackPane object
named root . We will need to use the same root.getChildren().add() method
call chain that we did in Chapter 6 , when we started developing our Splashscreen, to
add our iBagel object ImageView, which is referenced using iBagel.spriteFrame , to
the Scene Graph root object. I am going to add a method at this stage that will ensure
that we never forget this important add to Scene Graph step in our work process. I am
going to specifically address this stage in the Actor creation work process by making it
into its own method, which I am going to call .addGameActorNodes() . The creation
of this method body, and our first add Actor to Scene Graph programming statement,
would be accomplished using the following Java code, which is also shown (high-
lighted) in Figure 11-7 :
private void addGameActorNodes() {
root .getChildren().add( iBagel.spriteFrame );
}
 
 
Search WWH ::




Custom Search