Game Development Reference
In-Depth Information
will place these Java variable and object declarations, which can be seen highlighted in
Figure 17-1 , at the very top of the InvinciBagel.java class, right after the WIDTH and
HEIGHT constant declarations, and the Java code should look like the following:
int gameScore = 0;
Text scoreText ;
Figure 17-1 . Add an integer variable named gameScore and initialize it to 0, then add a Text object named scoreText
Mouse-over the wavy red error highlighting, and click next to the line of code con-
taining this error, to select it (which is shown using a light blue color). Next, use an
Alt-Enter work process to bring up the error resolution helper pop-up, shown at the
bottom of Figure 17-1 , and double-click on the “Add import for javafx.scene.text.Text”
option to have NetBeans write this Text class import statement for you.
Now we are ready to open the .createSplashScreenNodes() method, and instanti-
ate this Text object named scoreText , using a Java new keyword and the Text() con-
structor method. After you do this, you can call the .setText() method, and reference
the gameScore integer, using the String.valueOf() method, as well as positioning it in
your UI layout design, using the .setLayoutX() and .setLayoutX() methods, using the
following Java code shown in Figure 17-2 :
scoreText = new Text();
scoreText .setText (String.valueOf( gameScore ));
 
 
 
Search WWH ::




Custom Search