This is my first post here so please be gentle ;)
Im trying to make a tile map in XNA, and I got so far as generate my map randomly using a perlin method that generates a grayscaled texture that i use for tiledbased ground selection.
This is how i do it
internal void RenderNew(int mapWidth, int mapHeight)
{
_mapHeigth = mapHeight;
_mapWidth = mapWidth;
Tiles = new Tile[_mapWidth, _mapHeigth];
bool moveRowLeft = true;
//Create the map array
for (int y = 0; y < _mapHeigth; y++)
{
moveRowLeft = !moveRowLeft;
for (int x = _mapWidth - 1; x >= 0; x--)
{
Tile t = new Tile(x, y, _mapWidth, _mapHeigth)
{
Position = new Vector2(x * tileWidth + (moveRowLeft ? tileWidth / 2 : 0), (y * tileHeight / 2))
};
t.Ground = Tile.GroundType.Grass;
Tiles[x, y] = t;
}
}
//Generate the grayscaled perlinTexture
GenerateNoiseMap(_mapWidth, _mapHeigth, ref perlinTexture, 20);
//Get the color for each pixel into an array from the perlintexture
Color[,] colorsArray = TextureTo2DArray(perlinTexture);
//Since a single pixel in the perlinTexture can be mapped to a tile in the map we can
//loop all tiles and set the corresponding GroundType (ie texture) depending on the
//color(black/white) of the pixel in the perlinTexture.
foreach (var tile in Tiles)
{
Color colorInPerlinTextureForaTile = colorsArray[tile.GridPosition.X, tile.GridPosition.Y];
if (colorInPerlinTextureForaTile.R > 100)
{
tile.Ground = Tile.GroundType.Grass;
}
else if (colorInPerlinTextureForaTile.R > 75)
{
tile.Ground = Tile.GroundType.Sand;
}
else if (colorInPerlinTextureForaTile.R > 50)
{
tile.Ground = Tile.GroundType.Water;
}
else
{
tile.Ground = Tile.GroundType.DeepWater;
}
}
}
The texture sheet that i use thus contains texture for the Sand,Grass,Water and Deepwater. But it also contains tiles for creating nice overlaps, ie going from sand to water etc.
!Tried to post my tileset image but i couldnt case I'm to new on this site ;(
So my question is, how can i use the overlapping tiles as well? How do i know when to use a overlapping tile and in what direction?
All tiles also "know" its neighbour tile in all eigth directions (S,SE,E,NE,N,NW,W,NE)
//Thanx