Hexagons! Hexagons everywhere!
2013, Sep 13
I feel bored. Sometimes I feel so bored that I start walking around as if I were on a tiled map. And sometimes I like to switch from rectangular to hex-shaped tiles 😀
I’ve started working on a hex-based map renderer, just because, as I said. I’m bored.
Here’re the results so far:
And this is the tile texture:
I’m using XNA 4 (yeah I know, but that’s easy and I love to do everything by myself). Here’s part of the rendering code:
_hexTexture = this.Content.Load<Texture2D>("hex"); _hexOffset = new Vector2(_hexTexture.Width * 0.75f, -_hexTexture.Height * 0.5f); ..................... spriteBatch.Begin(); var hexPos = Vector2.Zero; for (int y = 0; y != 10; ++y) {
hexPos.Y = _hexTexture.Height * y * .5f; hexPos.X = _hexOffset.X * y;
for (int x = 0; x != 10; ++x) {
hexPos += _hexOffset; spriteBatch.Draw(_hexTexture, hexPos, Color.White);
} } spriteBatch.End(); Easy huh?