Game Development Reference
In-Depth Information
iBagel.spriteFrame.getBoundsInParent() .intersects (object.getSpriteFrame().getBoundsInParent());
It is important to note that just like the .getBoundsInLocal() and .getBoundsInPar-
ent() methods, this method also does not take the Node object's visibility attribute into
account. For this reason, an intersection test will be based on geometry for the Node
objects in question only, and for our ImageView spriteFrame Node objects, which
would be the geometry (dimensions) of their square (InvinciBagel) or rectangular
(Prop) Image containers. The default behavior of the Node class intersects(Bounds
localBounds) function is to check and see if local coordinates for a Bounds object that
is passed into this method call intersects with the local Bounds coordinates of the Node
that the .intersects() method call is being called “off of.” Next, let's take a closer look
at the Shape superclass, and its .intersect() method.
Using Shape Class Intersect: The .inter-
sect() Method
Just like a Node class (object) has an intersection method called .intersects() that is
used to determine when Node objects intersect, the Shape class also has an intersection
method, which you can use for Shape object intersection. This method is called .inter-
sect() (rather than intersects), so that these methods use different naming conventions.
This was probably done so developers won't be quite as confused between
Node.intersects() and Shape.intersect() methods. We will be using both of these in our
collision detection code later on in the chapter—first to detect when an ImageView
Node overlaps another ImageView Node, and then to do a Boolean intersection opera-
tion between our SVG data collision polygons (SVGPath objects named spriteBounds
within each Actor object).
The static method format for the Shape class's .intersect() method takes two Shape
objects in its parameter list, and this method returns a new Shape object. The new
Shape object that is created represents an intersection of (between) two input shapes.
As you can imagine, you can also use this method to do Boolean intersection genera-
tion for your vector artwork if you are using the Shape class and its subclasses for this
purpose. The format for the method is static Shape intersect(Shape
shape1, Shape shape2) , and the way that we're going to use it looks like this:
Search WWH ::




Custom Search