Game Development Reference
In-Depth Information
Shape shape =
SVGPath. intersect (invinciBagel. iBagel .getSpriteBound(),
object .getSpriteBound());
The reason that the Shape class's .intersect() method works so well for our collision
detection application is because we can later use a .getBoundsInLocal().getWidth()
method chain, to determine if a collision has occurred, or rather, if it has not occurred
by looking for a -1 empty value. We'll call this method chain that looks for a -1 off of
this new Shape object, which we will name intersection , in our .collide(object) meth-
od, using the following line of code:
if (intersection. getBoundsInLocal().getWidth() != -1 )
{ collisionDetect = true ; }
The way this .intersect() method works is that it only processes the geometric data
that occupies your input shapes, which in our application is the spriteBound SVGPath
object inside of our Actor objects. This is why we're using an SVGPath Shape object
(for maximum collision cage or polygon definition), purely for its geometric data val-
ues, and why we've installed this spriteBounds SVGPath Shape object container in our
Actor object design, because we intend on using this geometric data for our collision
detection, and not for vector illustration artwork (we are not stroking, or filling, the
SVGPath, for instance, and please, no subtle jokes here folks, we're learning game de-
velopment right now).
What this means is that the geometric areas of the input Shape objects being con-
sidered by the algorithm in the .intersect() method is “math based” only. This means
the algorithm is independent of the type of Shape (subclass) being processed, as well as
independent of configuration for the Paint object being used for filling or stroking
(please, again briefly resist the temptation to snicker one more time, for the sake of
learning Java 8 game development).
Before the final intersection calculation, the areas of the input Shape objects are
transformed to the Parent Node object's coordinate space (think: boundsInParent). In
this way, the resulting shape will only include those areas (mathematical geometric
areas, more precisely) which were contained in the areas of the two input Shape objects
passed into the method using the parameter list. Therefore, if there's any data
(something other than a -1 empty data value) in the resulting Shape object, which we
will be calling intersection in the code we will be writing next, there has been some
level of intersection, and even a small area of intersection (overlap) needs to signal a
detected collision.
Search WWH ::




Custom Search