【问题标题】:XNA Hexagonal Map TilepickingXNA 六边形地图拼贴
【发布时间】:2014-04-11 14:35:42
【问题描述】:

好吧,伙计们, 我在这方面遇到了很多麻烦。我根本想不出在 XNA 的六边形地图中实现瓷砖拾取的方法。在问这个问题之前我已经查过了,所有的答案都涉及复杂的算法和图表,我的小脑袋根本无法理解。所以我对你们的问题是:我怎样才能将鼠标悬停在图块上,如果我想选择它们?

如果您需要任何关于我的程序到目前为止的外观的参考,只需查看此链接,它实际上是相同的,只是我的地图较小。

http://www.xnaresources.com/default.asp?page=Tutorial:TileEngineSeries:3

谢谢!

【问题讨论】:

    标签: c# xna


    【解决方案1】:

    这是我存储但从未使用过的代码,它用于一个边向上的十六进制网格,因此通过一些小的调整它可以在您的示例中工作。这不是我的代码,不知道是谁写的。

    Hexagon[][] hexagons = new Hexagon[100][100];
    double hexagonHeight = 30;
    double hexagonWidth = 40;
    double halfWidth = hexagonWidth / 2;
    
    
    // Find rough coordinates of Hexagon at mousepoint
    private Hexagon getSelectedHexagon(MouseEvent mouse)
        {
            // These will represent which box the mouse is in, not which hexagon!
            int row = (int) (mouse.y / hexagonHeight);
            int column;
    
            boolean rowIsOdd = row % 2 != 0;
    
            // Is the row an even number?
            if (rowIsOdd) // No: Calculate normally
                column = (int) (mouse.x / hexagonWidth);
            else // Yes: Offset mouse.x to match the offset of the row
                column = (int) ((mouse.x + halfWidth) / hexagonWidth);
    
            // column is more complex because it has to
            // take into account that every other row
            // is offset by half the width of a hexagon
    
            return hexagons[row][column];
        }
    

    编辑:我刚刚找到作者 Hexagonal Grids, how do you find which hexagon a point is in?

    【讨论】:

    • 抱歉,但由于我对 XNA 和 C# 非常陌生,所以这段代码应该放在哪里,我必须更改哪些变量名/值才能使其正常工作?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-04
    • 1970-01-01
    • 1970-01-01
    • 2015-02-05
    • 1970-01-01
    • 2015-03-16
    • 2011-10-12
    相关资源
    最近更新 更多