1

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.

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.

FloWi
  • 151
  • 1
  • 8
  • Instead of manual calculations - possibly, Parent.impl_pickNode() can help you. It is a method, which is used to determine Node, on which click comes. Does it help? Or your trouble is different? – Alexander Kirov Apr 28 '13 at 10:50
  • Thanks for your answer. I can use your hint for another problem ;-) I figured out, that I really need to determine the intersecting node with my dragged card. Within the mousedragged-eventhandler, I iterate over every stack (Pane) and check for the intersection. I was just wondering, if there is a more elegant way. – FloWi Apr 28 '13 at 12:23
  • This method is marked as deprecated, and not supposed to be used by developers, so it is on your risk... – Alexander Kirov Apr 28 '13 at 12:30
  • I've filed an issue to make this method ( impl_pickNode() ) publicly available, you can track progress on that here : https://javafx-jira.kenai.com/browse/RT-30060 – Alexander Kirov Apr 28 '13 at 12:34
  • If your cards are all of the same size (are they?), then nodes intersecting is equal to the checking of impl_pickNode, where parameter is the same as each of 4 corners of card, which you are draging. – Alexander Kirov Apr 28 '13 at 12:36

1 Answers1

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.