Game Development Reference
In-Depth Information
then placed on the inside of an .intersect() method call. The complete conditional if()
construct looks like this:
if (
invinciBagel. iBagel .spriteFrame.getBoundsInParent(). intersects (
object .getSpriteFrame().getBoundsInParent()
) ){second level of collision detection in here}
This first level of collision detection code will check for the intersection of the iBa-
gel spriteFrame ImageView Node with the spriteFrame ImageView Node object that is
contained in each Actor object that will be passed into this .collide(Actor object) meth-
od call that we are coding currently.
This part of the code will check for a “top level” ImageView Node proximity (colli-
sion) before we call a more “expensive” Shape intersection algorithm, which we are
going to implement next, in order to confirm more definitive collision occurrence
(SVGPath collision polygon intersection). Remember that the code we're putting into
place inside of this .collide() method will be processed for each iteration of the for loop
(for each cast member) that is calling this collide(Actor object) method.
The Java code inside of this first conditional if() statement creates a Shape object,
named intersection , and sets it equal to the result of an SVGPath.intersect() method
call that references the iBagel SVGPath Shape object and an SVGPath Shape object
passed into the collide(Actor object) method. Both objects call a .getSpriteBound()
method, which we created back in Chapter 8 , to access the SVGPath Shape objects
needed for the .intersect(Shape1, Shape2) method call format. Your Java code,
formatted using two lines of code, for readability, should look like the following:
Shape intersection = SVGPath.intersect (
invinciBagel. iBagel .getSpriteBound(),
object .getSpriteBound() );
After we have this intersection data, we will use another conditional if() statement
to see if that intersection Shape object contains any collision data, and if it does (that is,
if it doesn't contain a -1 value) a collision has occurred.
The second nested if() statement will utilize the .getBoundsInLocal().getWidth()
method chain, called off of the intersection Shape object, and will check to see if it is
empty (returns a -1 value), or if a collision has occurred. The collision detection will
occur if the intersection Shape object's Bounds object contains any data value other
Search WWH ::




Custom Search