JakeBass Posted April 11, 2015 at 12:29 PM Report Share #581049 Posted April 11, 2015 at 12:29 PM (edited) Olá, estou a tentar a fazer um jogo 2D num elemento canvas. Alguma maneira de detectar interseção entre um path e vários círculos? se souberem de algum source code que me possa ajudar, ou uma library tb era fixe. para já tenho isto, mas não tou a perceber como fazer o loop: var dx = circle1.x - pathX_array; var dy = circle1.y - pathY_array; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < radius) { console.log("success"); } Edited April 11, 2015 at 01:06 PM by apocsantos geshi Link to comment Share on other sites More sharing options...
Solution JakeBass Posted April 11, 2015 at 05:02 PM Author Solution Report Share #581055 Posted April 11, 2015 at 05:02 PM (edited) já me safei, obrigado na mesma... fiz assim: function check(circle) { var check = false; for(var i = 0; i < pathX_array.length; i++) { var dx = circle.x - pathX_array[i]; var dy = circle.y - pathY_array[i]; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < 40) { check = true; } } return check; } Edited April 11, 2015 at 05:54 PM by apocsantos geshi 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