Game Development Reference
In-Depth Information
Figure 13-4 . Add conditional if() statements that check for up/down movement and sets jump/land sprite image state
As you can see in Figure 13-4 , our code is error-free, and we are ready to add sev-
eral layers of complexity to the left and right arrow key event processing code, since
these two keys are defining the direction (East and West) the InvinciBagel is traveling.
For this reason, these two conditional if() statement structures, in particular, need to be-
come more complex, because traveling East (to the right) will use original (isFlipH =
false) sprites, and traveling West (to the left) will utilize a mirrored version (isFlipH =
true) of each sprite, “flipping” the Image assets around the central Y axis.
Mirroring Sprites: Quadrupling Your Image Assets
from 9 to 36
Now let's go back into the existing .isLeft() and .isRight() conditional evaluation state-
ments, which are going to become quite “robust” (complicated) over the course of this
chapter, and let's add our spite mirroring capability. The JavaFX API has its mirroring
capability “hidden” in the ImageView class's .setScaleX() method call. Although we
are not going to scale our Image assets, as doing so causes artifacts in our pristine
PNG32 image assets, there is a little known trick that you can pass a -1 (negative 100%
scaling factor) value into a .setScaleX() method, to flip or mirror the Image asset
around the Y axis (or into the .setScaleY() method, to flip or mirror around the X axis).
Clearly we will need to also “undo” this in the other conditional if() structure by
passing a 1 (positive 100% scaling factor) into the same method call, which does not
 
Search WWH ::




Custom Search