1

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.

Community
  • 1
  • 1
Jax
  • 402
  • 7
  • 24
  • It struck me that this would also be on topic on Gamedev. – Jax May 14 '15 at 15:54
  • Have you looked at implementing your hex field as a tile-map https://github.com/libgdx/libgdx/wiki/Tile-maps. Especially: https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/maps/tiled/renderers/HexagonalTiledMapRenderer.java – Morrison Chang May 14 '15 at 16:00
  • @MorrisonChang I have looked at the option, but as far as I can tell you cannot programmatically create a .tmx (tile map) file. I am using the Android IDE (AIDE) to work on the game. – Jax May 14 '15 at 16:04
  • Answers should (if the IDE matters) treat this as if I am using Eclipse. AIDE is modeled after Eclipse. – Jax May 14 '15 at 16:25
  • Possible direction for investigation: http://gamedev.stackexchange.com/questions/67992/how-would-i-implement-procedurally-generated-tiles-in-libgdx – Morrison Chang May 14 '15 at 17:06
  • @MorrisonChang Thanks for the link. I guess I'll have a look at tiled map. I heard that a tile map is basically a xml file with references to pictures/textures and screen coordinates. Would this mean it is possible to manually write a tiled map? – Jax May 14 '15 at 17:27
  • Sorry don't have experience with that - just posting what I find. When I was thinking of doing a hex grid based game I did keep in mind that it just needed to look like it was hex even though the map tiles themselves may be rectangular. I can imagine a performance hit for having to calculate how to draw the grid constantly vs static tiles. Good luck. – Morrison Chang May 14 '15 at 17:52
  • You don't need a .tmx file to create a TiledMap in libgdx. You can create it in code if you like (or load from any other file format you create a loader for). – nEx.Software May 15 '15 at 13:13

1 Answers1

2

if I understand your question, mixing these links may help you create what you want:

1- http://www.alcove-games.com/advanced-tutorials/isometric-tile-picking/

2- http://www.gdreflections.com/2011/02/hexagonal-grid-math.html

3- look other link, code this repo: http://code.google.com/p/libgdx-tiled/source/browse/#svn%2Ftrunk%2Flibgdx-tiled-hex-desktop%2Fsrc%2Fgame%2Fhex

http://code.google.com/p/libgdx-tiled/source/browse/#svn%2Ftrunk%2Flibgdx-tiled-hex-desktop%2Fsrc%2Fapp%253Fstate%253Dclosed

http://code.google.com/p/libgdx-tiled/source/browse/releases/gdx-tests/TiledMapTest.java

http://code.google.com/p/libgdx-tiled/source/browse/trunk/libgdx-tiled-hex-desktop/src/game/Game.java

hope it will help, I do not put coments, because there were too many coments, I Thinks, if this information is not valid for you, notify me and delete

Angel Angel
  • 19,670
  • 29
  • 79
  • 105
  • Thanks for the answer, but I have already come across all these links. I would still keep it here in the hope that it will help someone in the future, though :) – Jax May 18 '15 at 15:17