C# / XNA - Map Tiling System
Good day, signed up hoping someone can maybe help me. I'm busy doing tech research for a Roguelike Survival game I want to make and while I have most of it functioning properly, I'm stuck with getting the tiling system to work seamlessly.
I've read countless resources pointing me to what I want, having this explain it properly (http://blog.rpgmakerweb.com/tutorials/anatomy-of-an-autotile/). The problem I'm facing is I'm struggling to interperet this into C# code using the XNA game libraries.
I have come so far as to being able to split up the tiles down to their quads. But can't seem to get the code together the stitch each part back together(which is mostly math as I would understand it). As another reference I have a LUA(Using LOVE Game library) tutorial which taught me basically just that I should break up the tiles (https://love2d.org/forums/viewtopic.php?t=7826), it does however show LUA script to do exactly as I want in C# / XNA, although I can't translate from LUA to C# either.
Example of my tileset split into pieces.
https://imgur.com/1lE3oFq
I've read countless resources pointing me to what I want, having this explain it properly (http://blog.rpgmakerweb.com/tutorials/anatomy-of-an-autotile/). The problem I'm facing is I'm struggling to interperet this into C# code using the XNA game libraries.
I have come so far as to being able to split up the tiles down to their quads. But can't seem to get the code together the stitch each part back together(which is mostly math as I would understand it). As another reference I have a LUA(Using LOVE Game library) tutorial which taught me basically just that I should break up the tiles (https://love2d.org/forums/viewtopic.php?t=7826), it does however show LUA script to do exactly as I want in C# / XNA, although I can't translate from LUA to C# either.
Example of my tileset split into pieces.
https://imgur.com/1lE3oFq
Comments
Below I've put some simple code which will draw a single sprite/tile over and over again to create a seamless floor.
In your case you'll want more than one sprite. One way to store that would be to replace private List<Vector2> tiles; with a list of a class that has position and sprite. Then when looping through just draw each items own sprite.
In Game.cs:
And then Environment.cs:
Thanks for the sample code on drawing the environment. It showed me an easier way to clamp the screen view to the map.
Here is a pastebin of my code used to cut the tiles up: pastebin.com/1ETvi4FV
See below images for sample data from my generation process.
https://imgur.com/KFtisnl - (Enlarged from 64x64 to 1024x1024 to view easily) This represents the generated map from which I extract the pixel color as a value for setting the tile texture, First 3 shades going from black to the 2nd gray is Water (at different depth), then it's sand, then ground/grass then mountain(White) in the middle.
http://imgur.com/87isVWB - This is when I draw the entire map.
Edit: While I have not yet solved my auto tile issue. I did sort out a majour problem I had with memory usage in my engine. Went from 64x64 tile map using 2.3 gb up to a 4096x4096 tile map using less than half of the memory at 730mb. Framerate is up from 27 to 98-100(max).