How to draw a hexagon map in libGdx using the Poly

2019-08-14 14:17发布

I recently asked this question on how to draw a hexagon in Android. After finding in the accepted answer that I would have to use umpteen lines of [repetitive] code (compared to the eleven when using regular Java Graphics and Polygon objects) I began to search for solutions. I found that libGdx has a Polygon class. I began trying to implement the code in the linked question (the code my question started out with) with slight modification, including replacing the graphics class.

I stumbled into this without originally checking the API and found that unlike the Java Polygon class the libGdx Polygon class only has one constructor. It is a float array to hold vertices. Unfortunately the code did not work after I placed the float vertices[6] in the constructor. No errors, just not my desired result.

Next I began the laborious task of searching through the API. I found several classes that I suspect can be used to achieve my desired effect (drawing hex map for my first strategy game). The Polygon class also has several methods that I suspect can be implemented.

I, like many other amateur programmers tend to learn best by example, however. I have always been able to reproduce my desired results after studying someone else's implementation. This problem is stumping me, so can someone give an example of how to do this with a detailed explanation. I have also done several Google searches to try and find an example. The hexagon math is simple enough, but drawing the hexagons seems to be a task.

(I would have added my code to the question had I not forgotten to back it up to Dropbox. I am currently, like most days, stuck using an iPad, not my trusty RCA Android tablet which I store my code on)

EDIT:

My actual question is the title. If it is not possible to do this in a straightforward or simple manner please explain why.