Game Development Reference
In-Depth Information
value, using the .isUp(), .isDown(), .isLeft(), and .isRight() method calls off of the in-
vinciBagel object reference. In this situation we want to look for a false value.
To accomplish this, we need to use the Java Unary Exclamation Point ! operator.
This reverses the Boolean value, so in our case, a false value from one of these method
calls would be represented by a !invinciBagel.isUp() construct, for instance.
To find out if more than one value is false at the same time, we'll need to implement
the Java Conditional AND operator, which uses two consecutive ampersand charac-
ters, like this && so; in this case, we will be using three of these && Conditional AND
operators, to tell the Java compiler that we want Right AND Left AND Down AND
Up to all be false . All of this logic will go inside of the if() evaluation area (inside of
the parenthesis). Inside of the curly braces, where the statements go if the if() evalu-
ation area is met (if up, down, left and right are all false), we will set the spriteFrame
ImageView object equal to the first Image object in the imageStates List<Image> ob-
ject using the .setImage() method call. Inside of that method call, we will use the .get()
method call on the imageStates List<Image> object, to get the first Image reference im-
ageStates(0) from the List<Image> object. This is the “waiting” sprite cel for the Invin-
ciBagel, which shows him waiting impatiently to be moved (animated). The Java code
for the construct would look like the following Java programming structure (I have in-
dented this for easier readability and learning purposes):
if ( ! invinciBagel.isRight() &&
! invinciBagel.isLeft() &&
! invinciBagel.isDown() &&
! invinciBagel.isUp() ) {
spriteFrame. setImage (imageStates. get(0) ); }
As is seen in Figure 13-2 , this first if() statement, representing “if none of the arrow
keys are being pressed,” is error-free. If you use the Run Project work process,
and test this code, you'll get the same result as you did in the previous chapter! To see
if this code works we must first make the InvinciBagel run, so that when we stop mov-
ing him using the arrow keys, we get this impatient “waiting” state, which actually
makes it a lot more effective (funny), when this wait is in the context of all this anim-
ated movement we're about to implement during the course of the chapter!
 
Search WWH ::




Custom Search