4

JavaFX Node class provides two intersect methods:

 intersects(Bounds localBounds);

and

 intersects(double localX, double localY, double localWidth, double localHeight);

When and how can I use these methods?

Angom
  • 721
  • 1
  • 11
  • 27

1 Answers1

4

as it name tells it is used to determine if a node is intersected with other node or not..

Example : If you're going to develop Zen pong game in javafx ,if ball hits the wall behind paddle then game over.

Code :

   private  Circle ball;
   private  Rectangle wall;
   if(ball.intersects(wall.getBoundsInLocal()) {
        //game over
    }
invariant
  • 8,758
  • 9
  • 47
  • 61
  • 3
    This is only correct if both nodes share a coordinate system. Otherwise, you need to transform the bounds before testing for collision. – Matthias Jan 23 '17 at 09:55