Game Development Reference
In-Depth Information
After this access control modifier, you will need to declare the method's return
type. This is the type of data that the method will return after it is called, or invoked.
Because the .start() method performs setup operations but does not return a specific
type of value, it uses the void return type, which signifies that the method performs
tasks but does not return any resulting data to the calling entity. In this case, the calling
entity is the JavaFX Application class, as the .start() method is one of the key methods
(the others being the .stop() and .init() methods) provided by that class to control the
life cycle stages of a JavaFX application.
Next, you will supply the method name, which, by convention (programming
rules), should start with a lowercase letter (or word, preferably a verb), with any subse-
quent (internal) words (nouns or adjectives) starting with a capital letter. For instance, a
method to display the splash screen would be named .showSplashScreen() or .dis-
playSplashScreen() and because it does something but does not return a value, would
be declared using this code:
public void displaySplashScreen() { Java code to display
splashscreen goes in here }
If you need to pass parameters, which are named data values that have to be oper-
ated on within the body of the method (the part inside the curly braces), these go inside
the parentheses that are attached to the method name. In Figure 3-2 the .start() method
for your bootstrap “HelloWorld!” JavaFX application receives a Stage object, named
primaryStage , using the following Java method declaration syntax:
public void start(Stage primaryStage) { bootstrap Java
code to start Application goes in here }
You can provide as many parameters as you like, using the data type and parameter
name pairs, with each pair separated by a comma. Methods can also have no paramet-
ers, in which case the parameter parentheses are empty, with the opening and closing
parentheses right next to each other, for example, .start(), and .stop().
The programming logic that defines your method will be contained in the body of
the method, which, as discussed previously, is inside the curly braces that define the
beginning and the end of the method. The Java programming logic that is inside meth-
ods can include variable declarations, program logic statements, and iterative control
structures (loops), all of which you will be leveraging to create your Java game.
Before moving on, let's focus on one other Java concept that applies to methods,
namely, overloading Java methods. Overloading a Java method means using the same
Search WWH ::




Custom Search