Game Development Reference
In-Depth Information
handling and character animation processing. The other sprites are better suited for use
with collision detection, so let's save those for later chapters in the topic.
Last Minute Details: Setting the isFlipH
Property
Next, I want to add in two more lines of code for what I call “bookkeeping,” because
we have installed isFlipH and isFlipV properties in our Actor superclass, so if we mir-
ror sprites around the X or Y axis, we need to be sure to set these variables correctly, to
reflect that (no pun intended) change to the Actor object, so that we can use this in-
formation in other areas of our game application programming logic. We will do this
using the Java this keyword, to refer to the iBagel object that we are coding for in the
Bagel.java class, and call the .setIsFlipH() method, using a false value if ScaleX prop-
erty has been set to 1, or a true value if the ScaleX property has been set to a value of
-1. It is important to note that we don't absolutely have to use the Java this keyword; I
am using it for clarity of meaning, and so you could also simply utilize the method call
without using dot notation, like this: setIsFlipH(false); if you like. The Java
code for doing this simple bookkeeping addition can be seen highlighted in Figure
13-18 , and looks like this:
if(invinciBagel. isRight() ) {
spriteFrame. setScaleX ( 1 );
this .setIsFlipH( false ); // nested conditional
if() processing ommitted for brevity
} if(invinciBagel. isLeft() ) {
spriteFrame. setScaleX ( -1 );
this .setIsFlipH( true ); // nested conditional
if() processing ommitted for brevity
}
 
Search WWH ::




Custom Search