How to draw a hexagon map in libGdx using the Polygon class?

狂风中的少年 提交于 2019-12-13 18:38:59

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/30241050/how-to-draw-a-hexagon-map-in-libgdx-using-the-polygon-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!