Game Development Reference
In-Depth Information
else {
REMOVED_ACTORS.add( actors[0] );
}
Notice that since we have converted the Actor... parameters (which are destined for
a List, but are not one yet) into an Array (because the compiler can count the fixed
number of items), so we can use the actors[0] notation.
Now that we have a way to add one or more Actor objects to the
REMOVED_ACTORS Set<Actor> HashSet, let's create a .resetRemovedActors() to
clear out the REMOVED_ACTORS data set. Before we clear the Set<Actor> object
we need to make sure all of the Actor objects contained within it are removed from the
CURRENT_CAST Actor List object, since that is what it is there for, so the first part
of this method will call the .removeAll() method off of the CURRENT_CAST Ar-
rayList<Actor> object and inside of this method pass over the REMOVED_ACTORS
Set<Actors> object. After that we can use the .clear() method call off of the
REMOVED_ACTORS object to reset it back to being empty, so that it can be used all
over again to collect Actor objects that need to be disposed of. The Java code, which is
shown in Figure 10-9 , should look like the following:
public void resetRemovedActors () {
CURRENT_CAST. removeAll (REMOVED_ACTORS);
REMOVED_ACTORS. clear ();
}
Next, we are going to look at how we can get NetBeans to code our CastingDirect-
or() constructor method!
CastingDirector() Constructor: Having NetBeans
Write the Code
There is a way that you can get NetBeans to write a constructor method for you, and
since it is a little bit “hidden,” I'll show you how to find it! I left the insertion-bar
cursor in Figure 10-10 , to show you that I clicked on the final keyword and the yellow
light bulb “ tip ” icon that appears, and the pale yellow pop-up tooltip message that I get
when I mouse-over the tip light bulb. The message that I get is the “Move initializer to
constructor(s),” and so I hit the Alt-Enter key combo that is suggested. Sure enough,
there is an option for NetBeans to write this constructor method code for me.
 
Search WWH ::




Custom Search