如何在JavaFX中使用Node Class的intersect()方法? [英] How to use intersect() method of Node Class in JavaFX?

查看:212
本文介绍了如何在JavaFX中使用Node Class的intersect()方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JavaFX Node类提供了两种交叉方法:

JavaFX Node class provides two intersect methods:

 intersects(Bounds localBounds);

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

我何时以及如何使用这些方法?

When and how can I use these methods?

推荐答案

因为它的名称告诉它用于确定一个节点是否与其他节点相交......

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

示例:如果您打算在javafx中开发Zen pong游戏,如果球击中桨后面的墙壁然后游戏结束。

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

代码:

   private  Circle ball;
   private  Rectangle wall;
   if(ball.intersects(wall.getBoundsInLocal()) {
        //game over
    }

这篇关于如何在JavaFX中使用Node Class的intersect()方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆