Game Development Reference
In-Depth Information
Figure 11-11 . Add a Java statement inside of the GamePlayLoop .handle() method invoking an iBagel.update() meth-
od
What the iBagel.update() Java statement does is to call the .update() method
for the Bagel object named iBagel on every pulse event. Anything that you put into this
.update() method will be executed 60 times every second. Any other Actor object that
you want processed at 60 FPS, simply add a similar .update() call to this .handle()
method.
Moving the iBagel Actor Object: Coding Your .up-
date() Method
Now we are ready to start developing the code that will move our InvinciBagel Actor
object around the screen. We will be refining this Java code during the remainder of the
book, as everything revolves around this primary Actor object, and his movement. This
includes where he moves (boundaries and collisions), how fast he moves (speed and
physics), and what he looks like when he moves (animating between sprite image cels
or “states”). All of this code will originate inside of the iBagel object's .update() meth-
od, and so we are going to start this lengthy journey by adding some basic code that
looks at the Boolean variables that are in our InvinciBagel.java class, and which hold
the arrow (or ASDW keys) key pressed and released states, and then process these
states using conditional If statements . The results of this conditional statement pro-
cessing will then move the InvinciBagel character on the screen (initially, later we will
add more advanced programming logic). We will eventually make this movement and
interaction more and more “intelligent.” The first thing that we will want to do is to
make the Boolean variables for up, down, left, and right visible to the Bagel class using
import static statements, as we did earlier in the chapter, to make the iBagel object vis-
ible to the GamePlayLoop class .handle() method. The four added import static state-
ments will look like this:
package invincibagel;
import static invincibagel.InvinciBagel. down ;
import static invincibagel.InvinciBagel. left ;
import static invincibagel.InvinciBagel. right ;
import static invincibagel.InvinciBagel. up ;
import javafx.scene.image.Image;
public class Bagel extends Hero {...}
Search WWH ::




Custom Search