Hey Bart - Check out the isPointInPath
canvas method. It should allow you to get a true
/ false
value based on whether your mouse coordinate is inside of your hexagonal path.
Here's a great stack overflow answer that shows what you're looking for: https://stackoverflow.com/questions/40509954/is-there-a-native-way-to-address-a-non-rectangle-object-on-canvas-in-js/40521863#40521863
Hope that helps 🙌
hi,
problem solved. I didn't use path 2d but wrote a similar function inside the class.
It seems to be working. Thanks for the tip!!
x and y present mouse coordinates and the horizontal size and vertical size present the size op the polygon.
isInsidePolygon(x , y , horizontalsize , verticalsize){
if( (x > (this.x - horizontalsize/2) ) && ( x < ( this.x + horizontalsize/2)) && (y > ( this.y - verticalsize/2)) && (y < (this.y + verticalsize / 2))){
return true
}
}
Want to participate?
Create a free Chris Courses account to begin