Game Development Reference
In-Depth Information
Figure 13-7 . Duplicate the nested if-else statement in .isLeft() structure, so InvinciBagel character runs both direc-
tions
The next thing that we'll need to is to add some Java code to control the running
speed of your InvinciBagel sprite. We will do this using two Integer variables: one to
serve as a framecounter and the other to hold the running speed value, which we can
change later on based on our vX (velocity along the X axis) variable to get a realistic
match between the speed the run cycle is animating at and the speed the sprite is being
moved across the screen.
Controlling Run Cycle Speed: Setting Up Your Anima-
tion Throttle Program Logic
In order to be able to “throttle” our run cycle sprite animation to achieve different
speeds, we need to introduce a “counter” variable called framecounter , which will
count up to a certain number of frames before we change a false (sprite cel 1) animator
value to true (sprite cel 2). We will also use a runningspeed variable, so that our anim-
ation speed is not hard-coded, and exists in a variable that we can change later on. This
allows us to have fine-tuned control over the speed (realism) of this run-cycle anima-
tion. Declare these two Integer (int) variables at the top of the Bagel.java class and ini-
tialize the framecounter variable to zero and set the runningspeed variable to a value of
6. Since both the false (!animator) and true (animator) second-level if() structures will
 
Search WWH ::




Custom Search