[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Hexagonal collision detection?



I don't have hexagonal buttons per se, but a hexagonal map. The effect is much the same, as you need to know which one has been clicked, although it's complicated somewhat by being viewed in 3D via pyopengl.

I draw all the hexes as quads with a hex map texture and transparent corners. For each I generate a second "mouse map" texture encoding color (e.g. (x,y,0)) that is drawn behind the scenes when the mouse is clicked, and I simply check what color is under the mouse and decode the clicked hex location.

-Jasper

rygoody wrote:
Hello, I need to make a clickable hexagonal button. The clickable area
needs to actually be hexagonal, it's an essential part of the gameplay
dynamic. So I can't just put a hexagon picture over a square button.
The clickable button itself needs to be a hexagon.

I was just gonna use a linear equation to define the diagonal sides of
the hexagon, then go through a for loop to test on each line if the
click was in or out of the hexagon. But this seems so very inefficient
to do in python.

So I just thought I'd ask, is there any class, or any functionality in
anything that would be more ideal for something like this?