Game Development Reference
In-Depth Information
al' bounds of the Node object, as in what you see on the screen, after the Node has
been moved , rotated , scaled , skewed , and so on.
The boundsInParent property is calculated by taking a local Bounds, defined by
the boundsInLocal property, and applying all of the transforms that have taken place,
including any calls to .set() methods for the following Node properties: scaleX , scaleY ,
rotate , layoutX , layoutY , translateX , translateY , and transforms (the Java Observ-
ableList). Just like the boundsInLocal property, this boundsInParent property will al-
ways contain a non-null value.
A resulting Bounds object will be contained inside of the coordinate space of a
Node object's Parent object, however, the Node object need not have a Parent (it can be
the Scene Graph root of the Scene) in order to be able to calculate the boundsInParent
attribute. Just like the .getBoundsInLocal() method, this method does not take the Node
object's visibility into account, so don't make the mistake of thinking you can circum-
vent your collision detection code by “hiding” your Actor Node, which, in our case, is
an ImageView Node subclass named spriteFrame .
Since it computes changes to the boundsInLocal property, it is logical that the
boundsInParent property will be computed whenever the geometry of a Node changes,
or when any transformations of that Node object occur. For this very reason it would be
a mistake to compute any of these values in a Node based on an expression that de-
pends upon this variable. For example, the X or Y variables of a Node object, or trans-
lateX, translateY shouldn't be computed using this boundsInParent property for the
purpose of positioning the Node, since prior positioning data is included in this prop-
erty, and thus would create a circular reference (somewhat akin to the infamous infin-
ite loop scenario).
Using Node Intersection: The .intersects(Bounds ob-
ject) Method
Another important method in the JavaFX Scene Graph Node class where collision de-
tection is concerned is the public boolean intersects(Bounds localBounds) method.
This method will return a true value if the Bounds object that specifies the local co-
ordinate space for the Node object that this method is being called “off of” intersects
the Bounds object passed into the method using the parameter, which is the Bounds ob-
ject of the Node that you are trying to determine intersection with. For instance, to de-
termine if the ImageView Bounds that contains the InvinciBagel sprite intersects the
ImageView Bounds that contains one of the Prop sprites, we would use the following
Java code format:
Search WWH ::




Custom Search