Game Development Reference
In-Depth Information
In case you're wondering what the SVGdata String object “M150 0 L75 200 L225
200 Z” does, it is shorthand for the following line drawing instructions (commands).
The M is a “Move Absolute” command and tells the line draw (or in this case a path
draw) operation to start at location 150,0. The L is a “Line Draw To” command and
tells the SVG data to draw a line from 150,0 to 75,200. The second L draws a line from
75,200 to 225,200, giving us two sides of the triangle shape. The Z is a “Close Shape”
command, which, if the shape is open, as ours is currently, will draw a line to close the
shape. In this case, that would equate to drawing a line from 225,200 to 150,0, giving
us three sides to our triangle shape, closing the open path, and giving us a valid colli-
sion detection boundary.
We will be replacing this with a more complex collision shape later on, during
Chapter 16 covering collision detection polygon creation, SVG data, and collision de-
tection logic. Our actual collision polygon will contain many more numbers, making
our Bagel() constructor method call unwieldy. As you might imagine, at that point in
the game (no pun intended), I will probably create a work process that will be used spe-
cifically for constructing collision shapes. This work process will show you how to
generate SVG polygon data using GIMP so that you can place SVG data into its own
String object, and reference that in your Actor object constructor. If you wanted to turn
collision data creation into its own method as well, this is how that would look, using a
(theoretical) .createActorCollisionData() method:
String cBagel ; // Create String variable named cBagel
(collision data Bagel) at top of class
private void createActorCollisionData() {
cBagel = "M150 0 L75 500 L225 200 Z";
}
private void createGameActors() {
iBagel = new Bagel( cBagel , 0, 0,
iB0,iB1,iB2,iB3,iB4,iB5,iB6,iB7,iB8);
}
You could also, later on, create a method for Image sprite List<Actor> object load-
ing. This would pass the ArrayList as a parameter, instead of a comma-delimited List.
Note that if you did this, you would also need to change your Actor abstract class con-
structor to take in an ArrayList<Actor> object, instead of an Image... List of Image ob-
jects.
Search WWH ::




Custom Search