Game Development Reference
In-Depth Information
framecounter=0;
}
Just like we want the animator Boolean variable to be reset to the false value any
time that all of the arrow keys are not in use, so to do we want the framecounter in-
teger variable to be reset to a zero value, any time that the arrow keys are not in use
(that is, are in a released state all at the same time). As you can see, we not only are set-
ting our sprite's waiting image state in this conditional statement, we are also using it
to reset our other variables as well.
Now we are ready to make our .isRight() and .isLeft() conditional if structures even
more complicated, as we will be nesting our Java logic three-nested conditional if
structures deep, to allow us to incorporate the framecounter and runningspeed integer
variables into our conditional if() structure. This will make our animation code “wait”
for six pulse event cycles before it changes the animator false value to true, and then
wait for another six pulse event cycles before changing it back to false.
This is fairly complicated Java code, at least for a beginner Java 8 title, but game
programming is inherently a complex undertaking, so let's go ahead and learn how to
code this throttle mechanism for our run-cycle animation.
I want to teach you about advanced topics during this topic, and this one (imple-
menting a speed throttle) is one that we simply can't avoid, as this run speed using a
simple Boolean alternating image state logic structure is not feasible to use in our
game, given the incredible speed of the JavaFX pulse event timing engine and its “con-
sole game” 60FPS frame rate, which is making our InvinciBagel sprite run cycle look
not only unrealistic, but painful to look at!
That said, this is about as complex as our Java 8 coding is going to get during this
chapter, at least, so hang on tight, and enjoy the ride (or rather, the run) as we create a
16 lines of Java code, nested conditional if() structure, in the next section. It will be a
lot of work, but the resulting run-cycle throttle control will be well worth the effort!
CodingYourRunCycleThrottle:TripleNestedIf-Else
Structures
The modification we are going to make to our Boolean animator if() structure is to
place an if(framecounter >= runningspeed){...} structure “around” the
animator=true; statement, so that the animator does not become true until six
pulse event loops have transpired. If the framecounter is equal to (or for some reason,
greater than) six, animator becomes true, and the framecounter gets reset to zero and
Search WWH ::




Custom Search