Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use intersect() method of Node Class in JavaFX?

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?

like image 549
Angom Avatar asked Oct 18 '25 04:10

Angom


1 Answers

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
    }
like image 83
invariant Avatar answered Oct 21 '25 20:10

invariant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!