How to use intersect() method of Node Class in Jav

2019-06-06 21:53发布

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?

1条回答
爷、活的狠高调
2楼-- · 2019-06-06 22:37

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
    }
查看更多
登录 后发表回答