1

我正在尝试通过实现一个小纸牌游戏来学习 javafx。我可以通过处理 mousePressed 和 mouseDragged 事件来制作可移动的卡片。

在鼠标按下时,我存储拖动的原点,在鼠标拖动事件中,我将 x-and-y-translations 应用于拖动的卡片。像魅力一样工作,没有任何延迟。(我

我的问题是确定拖到的卡片下的另一张卡片(节点)。你们有没有人意识到某事?像这样?

我试图避免手动计算来检查交叉点。

4

1 回答 1

2

There is a mechanism for that called "full press-drag-release gesture". The details are documented at MouseEvent and MouseDragEvent classes.

Basically, register an onDragDetected event handler on the dragged card and inside make two calls: card.startFullDrag() which enables the MouseDragEvents delivered to gesture targets card.setMouseTransparent() which makes the gesture targets picked through the dragged node

Now the dragging events continue to be delivered to the card, and the MouseDragEvents are delivered to the node picked below it. Don't forget to switch the mouseTransparent flag back after the gesture ends.

于 2013-04-29T13:15:54.193 回答