Game Development Reference
In-Depth Information
Testing the GamePlayLoop: Animating
the UI Container
Let's move one of the existing Scene Graph nodes, for example, the HBox layout con-
tainer parent (branch) node, which contains the four UI Button control elements, coun-
terclockwise around the InvinciBagel splash screen. You will do this by using a simple
if-else Java loop control programming structure to read (using a .get() method) and
control (using a .set() method) Pos constants that control (in this case) the corner of the
screen placement.
First, declare a Pos object named location at the top of the GamePlayLoop class.
Then, click on the error message highlighting, press Alt+Enter , and select the Import
Pos class option so that NetBeans will write your import statement for you. Next, in-
side the .handle() method, add an if-else conditional statement that evaluates this Pos
object named location and compares it with the four Pos class constants that represent
the four corners of the display screen, including BOTTOM_LEFT, BOTTOM_RIGHT,
TOP_RIGHT, and TOP_LEFT. Your Java code should look like the following if-else
conditional statement Java program structure (see also Figure 7-20 ):
Pos location ;
@Override
public void handle(long now) {
location = InvinciBagel.buttonContainer. getAlignment() ;
if (location == Pos.BOTTOM_LEFT) {
InvinciBagel.buttonContainer.setAlignment(Pos.BOTTOM_RIGHT);
} else if (location == Pos.BOTTOM_RIGHT) {
InvinciBagel.buttonContainer.setAlignment(Pos.TOP_RIGHT);
} else if (location == Pos.TOP_RIGHT) {
InvinciBagel.buttonContainer.setAlignment(Pos.TOP_LEFT);
} else if (location == Pos.TOP_LEFT) {
InvinciBagel.buttonContainer.setAlignment(Pos.BOTTOM_LEFT);
}
}
 
Search WWH ::




Custom Search