Share Posted May 20, 2016 Hi, First, sorry for my english, I am french. I made some particles, and I want to erase them with an eraser. There is no draggable element, the eraser moves by himself automatically (with a bezier path). I want the particles under the eraser to disappear. I am trying to use the HitTest() function but i cannot figure out to use it without a draggable element. Thanks for your help. David. See the Pen GZbxYL by DavidN (@DavidN) on CodePen 1 Link to comment Share on other sites More sharing options...
Share Posted May 20, 2016 Draggable has a static hitTest() method that you can just feed two elements into, but beware that it simply uses the bounding boxes to measure overlaps, so it's not literally pixel-perfect for rotated or oddly-shaped things (that'd be a lot more processor-intensive). For example: //simple overlap test if (Draggable.hitTest(element1, element2)) { //do stuff } You can also check that a certain amount or percentage of the elements overlap. See the docs: http://greensock.com/docs/#/HTML5/GSAP/Utils/Draggable/hitTest/ 3 Link to comment Share on other sites More sharing options...
Share Posted May 22, 2016 You would need to do SAT collision detection... See the Pen 40b18190c60161960d8d12ff4fa71d1d?editors=0010 by osublake (@osublake) on CodePen That's very hard to do with HTML elements because you have to calculate the current transformation matrix for every point on your elements. I think this would be easier to do with SVG masks. See the Pen a9eb0affd4f2c0c9f05a0e33168fe185 by osublake (@osublake) on CodePen 3 Link to comment Share on other sites More sharing options...
Author Share Posted May 23, 2016 Thanks a lot for your help guys. It's a bit more complicate than I expected ! I will try it soon. I will let know know if I make it ! Link to comment Share on other sites More sharing options...
Author Share Posted May 24, 2016 I finally made it ! See the Pen GZbxYL by DavidN (@DavidN) on CodePen I have used a ticker event listener to listen when there is a hit between my eraser and my particles TweenMax.ticker.addEventListener("tick", hitDetection); and the hitTest function //simple overlap test if (Draggable.hitTest(element1, element2)) { //do stuff } If you have an idea to improve the code, please tell me. Thanks. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now