Game Development Reference
In-Depth Information
it, but testing it in NetBeans is the only real way to find out for sure! Let's do that next.
This is getting kind of exciting!
Testing the InvinciBagel Sprite Boundaries: Run
Project
Now it is time to use the NetBeans Run Project work process and test the
.setBoundaries() method, which now gets called after the .setXYLocation() method but
before the .moveInvinciBagel() method. So the logical progression as it sits now is
check keypressed and set X and Y location based on that, then check to make sure you
have not gone past any boundaries, then position the sprite.
As you can see in Figure 12-19 , the InvinciBagel character now stops at all four
edges of the screen. On the left and right sides he stops a short distance away from the
side of the screen because the sprite is centered in the ImageView area, but once we get
him running, which we will be doing in the next chapter covering how to animate the
character's movements, this will look at lot closer to the edge of the screen. We always
have the option to adjust our leftBoundary and rightBoundary variable algorithms at
the top of the Bagel.java class, which allows us to “tweak” the boundary limits value
later on, as we continue to refine our code.
Figure 12-19 . Testing the InvinciBagel character movement; shown as stopping at the top and bottom boundary lim-
its
Now that we have both organized and encapsulated our code, got the sprite move-
ment working and set the boundaries for the edges of the screen, we can start to look at
implementing the different sprite image states so that when combined with the key
movement, we can start to create a more realistic InvinciBagel character action figure!
 
 
Search WWH ::




Custom Search