Share Posted February 23, 2022 Hi again, in my codepen example - hittest works as expected but only in the first instance. What would be the recommended way to detect a collision with multiple dynamically created elements? See the Pen eYeKypy by njvan (@njvan) on CodePen Link to comment Share on other sites More sharing options...
Solution Solution Share Posted February 23, 2022 Hi njvan, Calling hitTest like you are doing will only call it on the first .pad element and the first .note element. You would need to loop through each pad and each note to do it like you want. That's going to be a little wasteful, so it would be best to only check notes that are in the same track as the pad. To further optimize, you should only check notes that are active. Notice how I added an active class to the element right before it animates and remove it right after it animates. If you need any help understanding what I did here, just let me know. See the Pen wvPxwRE by GreenSock (@GreenSock) on CodePen 2 1 Link to comment Share on other sites More sharing options...
Author Share Posted February 24, 2022 That's amazing! Adding the active class was genius. I had started down a rabbit hole of trying to get the currently animating element in the timeline. This is much simpler. Thank you so much, @OSUblake! 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