Game Development Reference
In-Depth Information
version of our game, and for a future multi-player version, this would include the In-
vinciBagel Hero Actor object and the Enemy Hero Actor object as well.
Creating a Hero Superclass: Motion Act-
or Attributes
Let's create our public abstract Hero class next! This class will be the foundation for
motion sprites that we will be creating for the game during this topic. Create your
Hero.java class in NetBeans, and declare it as public abstract class Hero
extends Actor . Since we have done a lot of the “heavy lifting” in the Actor class,
you will not have to create an ImageView to hold the sprite Image assets, or the
List<Image> ArrayList object loaded with a List object filled with Image objects, or an
SVGPath Shape object to hold the collision shape SVG polyline (or polygon) path
data.
Since we don't have to declare any primary attributes, as those are inherited from
the Actor superclass, the first thing we are going to do is to create a Hero() constructor
method. This will contain your collision Shape data in a String object, the sprite X, Y
location, and the Image objects that will be loaded into the List<Image> ArrayList ob-
ject. After we create a basic Hero() constructor method, we will finish figuring out the
other attributes (or variables) that your motion sprites will need to contain, just like we
did when we designed the Actor superclass.
Remember that you already have the spriteBound SVGPath Shape object, im-
ageStates List<Image> ArrayList object, SpriteFrames Image object and iX and iY
variables constructed in the Actor class using Actor() method. We will also need these
to be in place in order to be able to code our Hero() constructor method. Since these are
all already in place, due to the java extends keyword in the Hero class declaration, all
we have to do is use the super() constructor method call and pass these variables from
the Hero() constructor up to the Actor() constructor. This will automatically pass these
variables up into the Hero class for our use, using the Java super keyword.
Therefore, we have everything we need to be able to code our core Hero() con-
structor method, so let's get into that now. The Hero() constructor will take in the same
number of complex parameters as the Actor() constructor. These include your collision
shape data, contained in the String object named SVGdata , an “initial placement” X
and Y location for the sprite, and a comma separated list of the Image objects (cels or
frames) for the sprite, which I named Image... spriteCels. This Image... designation,
which needs to be at the end of your parameter list, because it is “open ended,” means
Search WWH ::




Custom Search