Game Development Reference
In-Depth Information
Figure 8-8 . Add initialization values to the eight new fixed sprite pivot and state definition variables you just declared
The remaining methods in the Actor class will be what are commonly termed “get-
ter” and “setter" methods because these methods provide access to the data variables
inside of the class. Using getter and setter methods is the correct way to do things, be-
cause doing this implements the Java concept (and advantage) of encapsulation , which
allows Java objects to be self-contained vessels of object attributes (variable data val-
ues) and behaviors (methods).
Accessing Actor Variables: Creating Getter and Setter
Methods
One of the really powerful (and time saving, as you are about to see) features of
NetBeans is that it will write all of your .get() and .set() methods for each of your ob-
ject and data variables for you automatically. We will be using this handy feature dur-
ing this topic whenever possible, so you can get used to using this time saving feature
to write lots of Java 8 code for you, accelerating your Java 8 game code production
output! You access this auto-coding feature by using the Source menu, and its Insert
Code submenu, as can be seen in Figure 8-9 . As you can see, there is also a keyboard
 
 
Search WWH ::




Custom Search