Game Development Reference
In-Depth Information
Initializing Sprite Control and Definition Variables in an
Actor Constructor Method
For now we are going to initialize our pivot point
pX
and
pY
to
0
(the upper left corner
origin) and all of our Boolean flags to a value of
false
except for the
isFixed
variable,
which for a fixed sprite will always be set to a value of
true
. We will do this using the
following eight lines of Java code inside of the current Actor() constructor method and
underneath the initial four lines of code in the method that deal with configuring the
Actor object using the method parameters:
pX = 0;
pY = 0;
isAlive = false;
isFixed = true;
isBonus = false;
hasValu = false;
isFlipV = false;
isFlipH = false;
We could also do this using
compound initialization statements
. This would re-
duce the code to three lines:
px = pY =
0;
isFixed = true;
isAlive = isBonus = hasValu = isFlipV = isFlipH =
false;
As you can see in
Figure 8-8
we have now coded nearly three dozen lines of error-
free Java 8 code, and we are ready to create the rest of the .get() and .set() methods that
will make up the public abstract Actor superclass.