Game Development Reference
In-Depth Information
CHAPTER 16
Collision Detection: Creating
SVG Polygons for the Game Act-
ors and Writing Code to Detect
Collision
Now that we have implemented digital audio for our game sound effects and short-loop
music, as well as implemented our digital imaging related classes that create motion
sprites (characters) and fixed sprites (props), we will now delve into the other major
genre or area of new media: vectors . Vectors are utilized in 2D illustration software
(InkScape) as well as 3D modeling and animation software (Blender), and use math to
define the shapes that are used to create the 2D or 3D artwork. This makes vectors the
perfect solution for defining custom collision shapes that perfectly encase our sprites,
so that instead of using a complex array of pixels to detect collision, we use a far simpler
(and far more memory and processor efficient) collision polygon , that will perfectly sur-
round our sprite.
Fortunately for us, the JavaFX SVGPath class in the javafx.scene.shape package
allows us to use custom SVG Path (Shape) data to define our sprite collision boundaries.
Not only that, but this SVGPath class (object) is also highly efficient, as it has zero
properties, only a few methods, and a simple SVGPath() constructor method, as you
have seen already in Chapter 8 . This means that using the SVGPath class (object) is rel-
atively memory and processor efficient . In fact, the only method that we will need to
use is the .setContent() method that we used in our Actor class constructor method in
Chapter 8 . Since we'll do this once, at game start-up, the SVG Path collision data will
Search WWH ::




Custom Search