Game Development Reference
In-Depth Information
and Hero (motion sprites) objects are in the scene, so that you only involve the fewest
possible number of actors in your collision detection code (algorithms). This is a func-
tion of optimizing your game programming logic so the game plays well across all
platforms.
Figure 10-1
.
Create a CastingDirector.java actor casting and tracking engine to keep track of Actor and Hero objects
Before we code our CastingDirector.java class, let's take some time to learn about
Java collections, generics, and the List, ListArray, Set and HashSet classes that we are
going to use to create these actor management tools.
List and ArrayList: Using java.util List
Management
First, let's cover the
public
class
ArrayList<E>
because it is a class, and then we will
look at List as that is an Interface, and not a Java class. In case you are wondering what
the
<E>
stands for, it stands for
Element
, if you see a
<K>
that stands for
Key
, if you
see a
<T>
that stands for
Type
, and if you see a
<V>
that stands for
Value
. The <E>
gets replaced by an element (object) that you're using in an ArrayList. In our case that
is ArrayList<Actor> as CastingDirector.java class ArrayList (and Set) will reference
Actor objects (subclasses of Actor superclass). The class hierarchy is as follows: