Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stage.getIntersection returns null when called from dragmove handler #601

Closed
gotdan opened this issue Sep 9, 2013 · 7 comments
Closed

Comments

@gotdan
Copy link

gotdan commented Sep 9, 2013

Hi,

I'm trying to highlight drop targets as a shape is dragged over them. However, the getIntersection function seems to return null when called during a drag (even with hard coded coordinates). Is this a bug, or is there a better way to determine when a dragged shape is over one of the allowed drop shapes?

Thanks,
Dan

@lavrton
Copy link
Contributor

lavrton commented Sep 11, 2013

👍 Really need to such stuff as detect drop shape. I think best realisation is events "dragover", "dragout".

@ericdrowell
Copy link
Owner

Let me clarify a bit on what's happening. Currently, when you drag and drop a shape, the hit graph is not redrawn on each animation frame to help improve drag performance. As a result, shapes are temporarily undetectable.

What you really need is true collision detection + dragover / dragout. I have plans to support these, but haven't gotten around to it yet.

@gotdan
Copy link
Author

gotdan commented Sep 12, 2013

Thanks Eric - I suspected it might be a performance optimization.

Adding collision detection with "dragover" and "dragout" would be really useful! For now, I'm getting the mouse position on each "dragmove" event and looping through the drop targets to find any overlap (I suspect this is pretty inefficient, but it seems to work ok in my small project :)

@lavrton
Copy link
Contributor

lavrton commented Mar 7, 2014

You can move draggable shape to temporary layer on dragstart, then call getIntersection to detect collision. See demo: http://jsbin.com/pecor/1/edit

@lavrton lavrton closed this as completed Mar 7, 2014
@danieldunderfelt
Copy link

The tempCanvas method doesn't seem to work anymore, at least not using that jsbin code. The stopDrag and startDrag methods seem to make the dragstart (and dragend) event behave like dragmove, ie it fires all the time during the drag, which messes things up. And I didn't get it to work without those drag methods.

Is there a way to turn on the hitgraph during dragging?

@lavrton
Copy link
Contributor

lavrton commented Aug 11, 2014

I think we should implement easy way to change layer while dragging and add drawHitOnDrag configuration.
As dirty workaroud look there: http://jsbin.com/pecor/3/edit

@flogiston
Copy link

Thanks @lavrton for the workaround. Saved me a lot of frustration :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants