在JavaFX中被鼠标拖动:确定要在其上拖动另一个节点的卡节点 [英] mousedragged in JavaFX: determine the card node over which another node is dragged

查看:82
本文介绍了在JavaFX中被鼠标拖动:确定要在其上拖动另一个节点的卡节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过实施一些纸牌游戏来学习javafx.通过处理mousePressed-和mouseDragged-events,我可以使卡移动.

I'm trying to learn javafx by implementing a little card-game. I am able to make a card movable with handling the mousePressed- and mouseDragged-events.

在按下鼠标的时候,我存储了拖动的起点,并且在鼠标拖动的事件中,我将x和y转换应用于拖动的卡.像魅力一样工作,毫不拖延. (我

In mouse-pressed I store the origin of the drag and within the mouse-dragged-event I apply x-and-y-tranlations to the dragged card. Works like a charm and without any delay. (I

我的问题是确定被拖动的卡下的另一张卡(节点).你们有没有意识到某事?这样吗?

My problem is to determine another card (node) under the dragged card. Has any of you realized s.th. like this?

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

I tried to avoid manual calculations to check the intersections.

推荐答案

有一种机制称为完全按下-拖动-释放手势".详细信息记录在MouseEvent和MouseDragEvent类中.

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

基本上,在拖动的卡上注册onDragDetected事件处理程序,并在内部进行两次调用: card.startFullDrag()启用将MouseDragEvents传递到手势目标 card.setMouseTransparent()使得通过拖动节点拾取手势目标

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

现在,拖动事件将继续传递到卡上,而MouseDragEvents将传递到卡下选择的节点上.不要忘记在手势结束后再将mouseTransparent标志切换回去.

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.

这篇关于在JavaFX中被鼠标拖动:确定要在其上拖动另一个节点的卡节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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