-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
Arcade.body.overlapX/overlapY should be retrievable from Arcade.overlap() #641
Comments
If you set a customSeparateX/Y on the body then it will go into the separationX/Y methods, but not actually separate them, instead the overlapx/y values are populated and it's entirely up to your code to sort out how to move them apart again. This will only work if you collide the objects, not overlap them. separateX/Y are protected internal methods used by collide, and were never meant to be called directly. None of your process or collision callbacks can be fired if you hit them directly. |
I see... unfortunately that won't help me as I can't use collision tests while dragging a sprite (or so it appears). I ended up 'rolling my own' overlapX/Y tests in update() so I could use it both with velocity and with dragging, but it would really be great to have an optional param to the Arcade.overlap() method that would allow for retrieving these values. I understand Arcade.overlap is suppose to be a fast method of just determining _if_ two sprites overlap, so that's why I'm suggesting the optional param so it can remain fast for those who don't need the overlapX/Y values, but still allow it for people who do. Oh, also btw: separateX/Y are not marked as in the docs, which sounds like they should be. Since this is an enhancement request now, you can close the report (unless it's OK for me to close it). |
I've tagged this as enhancement, please leave it open for now. I'll close it once I've added it into dev. |
…operties are set to the amount the two bodies overlapped by. Previously they were zero and only populated during the separation phase, but now the data is available for just overlap checks as well. You can then use these values in your ovrelap callback as required - note that they are changed for every check, so a Sprite overlap tested against 10 other sprites will have the overlapX/Y values updated 10 times in a single collision pass, so you can only safely use the values in the callback (#641)
I know it's quite old, but I've just added support for this :) |
My scenario is that I have two sprites that should pass over each other (not collide), and those sprites can be either both me moved with velocity or one of them can be dragged manually by the user onto the other sprite. In both cases, I need to be able to determine the amount of overlap in both directions.
I am able to get the kind of overlapping behavior by using the Arcade.body.overlap() function, but you can't test for the overlapX/overlapY values when this method is triggered.
Here's an example of the code I'm currently using testing for dragging a sprite ("brick") over another sprite ("bags"):
Using the code above, it triggers the overlap method, but not the separateX/separateY methods.
I looked up Arcade.body.overlapX/overlapY in the source and discovered that the only time these values are filled with something other than 0 is when you use the Arcade.separate(), Arcade.separateX, or Arcade.separateY() methods. Unfortunately, this also turns on collision tracking, which also prevents triggering these methods if you are dragging a sprite (btw, this is also true even if you pass true for the 'overlapOnly' parameter to Arcade.separateX/separateY).
So unless there's a way to drag and still get overlapX/overlapY to work, I would suggest adding this to the Arcade.overlap() method.
The text was updated successfully, but these errors were encountered: