Game Development Reference
In-Depth Information
Adding Sprite Control and Definition Variables to an
Actor Class
The next part of the process is easy, from a coding standpoint, as we will be declaring
some more variables at the top of the Actor class. From a design standpoint, this is
more difficult, however, as it requires that we think ahead as far as possible, and specu-
late about what variable data we will need for our sprite actors, both fixed and motion
sprites, to be able to do everything that we want to during the construction of this
game, as well as during its game play.
The first additional variables I am going to declare after the iX and iY variables are
the pX and pY pivot point variables. I had originally placed these in the Hero subclass,
which we're going to create next, once we are done with the creation of this Actor su-
perclass. The reason I moved these “up” to the Actor superclass level is because I
wanted to have the flexibility of rotating fixed sprites (treasure and obstacles) as well
as motion sprites. This gives me more power and flexibility where level and scene
design purposes are concerned. These pivot point X and Y variables would be declared
as protected double data variables, and would be done using the following two lines
of Java code:
protected double pX ;
protected double pY ;
Next, we need to add some boolean “ flags ” to our Actor class (object) definition.
These will indicate certain things about the sprite object in question, such as if it is
Alive (for fixed sprites this will always be false) or Dead , or if it is Fixed (for fixed
sprites this will always be true, and true for motion sprites that are not in motion) or
Moving , or Bonus objects, indicating additional points (or lifespan) for their capture
(collision), or Valuable , indicating additional powers (or lifespan) for their acquisition
(collision). Finally, I'm defining a Flip Horizontal and Flip Vertical flag, to give me
four times the flexibility with (fixed or motion) sprite image assets than I would have
without these flags in place.
Since JavaFX can flip or mirror images on the X or Y axis, this means I can reverse
a sprite direction (left or right) using FlipV or orientation (up or down) using FlipH.
These six additional Boolean flag fixed (Actor) sprite attributes will be declared by
using protected boolean data variables, using the following six lines of Java 8 code, as
is shown (error free, no less) in Figure 8-7 :
 
Search WWH ::




Custom Search