Game Development Reference
In-Depth Information
Figure 8-4 . Create a New Class in NetBeans, name it public abstract class Actor, and add in the primary Actor vari-
ables
These five variables or attributes hold the “core” properties for any sprite; the
spriteFrame ImageView and the List<Image> ArrayList of Image assets (one to many
visible states) that it holds (this defines what the sprite looks like), the spriteBound col-
lision Shape area (defines what is deemed to have intersected with the sprite), and the
X, Y location of the sprite on the display screen.
These are also the five variables that will be configured using your Actor() con-
structor method, as well as your Hero() constructor method later on. First we will cre-
ate the Actor() constructor; after that, we will add in all the other variables that we will
need every Actor subclass to include.
After we create all of the other variables for the Actor class, which are not set using
the Actor() constructor method, we will initialize these to hold their default values in-
side of the constructor method, and finally we will have NetBeans create .get() and
.set() methods for our variables using an automatic coding function which you'll really
like.
The parameters that we will code to pass into this Actor() constructor will include
the String object named SVGdata, which will contain a string of text defining the
SVGPath collision shape, as well as the sprite X, Y location, and a comma delimited
List of Image objects. The SVGPath class has a .setContent() method that can read or
“parse” raw SVG data strings, and so we will use this to turn the String SVGdata vari-
able into our SVGPath collision Shape object.
We will not be implementing the collision code, or SVGPath Shape object during
this chapter, or the next for that matter, but we need to put them in place, so we can use
them later during Chapter 16 on collision detection processing and how to create colli-
sion polygon data using the GIMP and PhysEd (PhysicsEditor) software packages.
The Actor constructor method that we will be creating will follow the following
constructor method format:
public Actor(String SVGdata , double xLocation , double
yLocation , Image... spriteCels )
Later on if we need to create more complex Actor() constructor methods, we can
“overload” this method by adding other more advanced parameters, such as pivot point
pX and pY, for instance, or the isFlipH or isFlipV boolean values, to allow us to mirror
fixed sprite imagery horizontally or vertically. Your Java code will look like the follow-
ing:
Search WWH ::




Custom Search