Game Development Reference
In-Depth Information
make a whole lot of sense (normally) as our Image scale is already 100% (not scaled)
but in light that the -1 scale-flip factor might have been set previously, this is how we
make sure that mirroring is disabled and we are again using our original sprite Image
assets for that particular state. Your newly upgraded Java statements implementing
sprite mirroring should now look like the following code, which is also shown high-
lighted in Figure 13-5 :
if(invinciBagel. isRight ()) {
spriteFrame. setImage (imageStates. get(1) );
spriteFrame. setScaleX (1);
}
if(invinciBagel. isLeft ()) {
spriteFrame. setImage (imageStates. get(1) );
spriteFrame. setScaleX ( -1 );
}
Figure 13-5 . Add a .setScaleX() method call to the .isRight() and .isLeft() evaluations to flip the sprite around the Y
axis
As you can see in Figure 13-5 , your Java code is still error-free. It is interesting to
note that we are calling the sprite mirroring method on the spriteFrame ImageView
object, and not on the Image assets inside of this ImageView. This is of tantamount im-
portance, because it means that we can use this one single line of code inside of
.isRight() and .isLeft() to flip whatever sprite state (image) is showing inside of an
ImageView! That's highly optimized programming!
 
 
Search WWH ::




Custom Search