Hexagonal canvas/button

Does anybody know if it is possible to make an regular hexagonal shaped button? Or a canvas would actually be better, because i’m making an hex based grid

with a canvas you can do anything you want…
create a hex grid… and when the user clicks, calculate which hexagon the mouse coordinates are within

Could you please indicate how to proceed?

i’m kind of new in this whole programming world… :’)

  1. Study the documentation for canvas. See http://documentation.xojo.com/index.php/Canvas
  2. Have a look at the many drawing examples that come with Xojo.
  3. Do a Goggle on “how to draw a hexagonal grid”. For instance Draw a hexagonal grid in C# - C# HelperC# Helper doesn’t look too complicated.
  4. Try to convert this to Xojo and come back with questions on what you can’t translate.

Remember: crawling, walking and then running. Don’t start with running.

What you need to know is in this article.
All you need to do is draw your hexagons and color them in on an offscreen image.


Well i already draw my grid… the problem is i dont know how to interact with it… or each hexagons individually

Did you read the article?

Detect a click on on your grid, look at the matching color picture, find the RGB value of the pixel at that position, then do something in response.

If you create a polygon shape of the same size as the hexagon, you can display a color hexagon in that cell briefly to show it has been clicked.

Remember, we have no idea what you want to do with your grid.

Jeff just gave you the principle of varied shapes buttons : detect the color of the pixel under the click, and if it is the color of the hexagon, time for action…

Is this solution helpful?

Also, scrolling down on this, there is a section etitled “Pixel to Hex”

It’s for a school project and I have to programm a game that ressembles Civilization 5.

Thank you very much for your help guys! ! appreciate it a lot!

I have a hard time reconciling those two statements…
What kind of a computer course would assign “something that resembles Civ5” in what I am assuming is an entry level class

Use the right tool for the job.
Xojo is great, and makes Cross Platform software super easy.

But you’re really going to want to use a game engine for that.

Well i realise i might of over stated what i meant. The game won<t actually ressemble civ 5 but the concept is the same, with a lot less mechanics, less details and bad graphics