Game Development Reference
In-Depth Information
Figure 8-5 . Create a constructor method to set up fixed Actor sprite subclasses with collision shape, Image list, loc-
ation
Next, let's code the other crucial method for this class, the abstract .update() meth-
od, and then we can add the rest of the Actor class fixed sprite attributes that we will
need. After that, we can initialize the additional variables inside of the Actor() con-
structor method. Finally we will learn how to create “getter and setter” methods for the
Actor class, before we move on to use this new custom Actor superclass to create our
other Hero motion sprites subclass.
Creating an .update() Method: Connect to
GamePlayLoop Engine
The most important method for any sprite class, other than the constructor method that
births it into existence, is the .update() method. The .update() method will contain the
Java 8 code that tells the sprite what to do on every pulse of the GamePlayLoop. For
this reason, this .update() method will serve to “wire” the Actor sprite subclasses cre-
ated using our Actor superclass and Hero subclass into the GamePlayLoop timing en-
gine that we created in Chapter 7 .
Because we need to have an .update() method as part of every Actor object (actor
sprite) in our game, we'll need to include an “empty” (for now) abstract .update()
method in the Actor superclass we are coding currently.
 
Search WWH ::




Custom Search