ArchangelEngine Dev Log 4: Tilemap loading from files.
HTML-код
- Опубликовано: 25 авг 2024
- Hello all! The support has blown me away, I was not expecting anybody to watch these videos. Today, my engine now has the ability to load a map from a .txt file. As you can see in the video, I have a 25x20 coordinate plane basically of numbers. 3 tells the engine to make water, 1 makes dirt, and 2 makes grass. This is an exciting step for the engine and means we can make levels now and load them in a flash whenever needed!
I am cheering you again.
hi, i'm still trying to figure out how 2D tile-based maps are drawn, do you use double-for looping to parse that .map file and draw on screen? i just don't know what is the right way to actually draw the map in 2D games
I have actually since moved on in later revisions to the Map being an entity that has a tileComponent attached to it, but yes, when I was doing it this way, I was using a nested for-loop. Since my map is 25 tiles wide and 20 tiles tall, I used something like this below, where SizeX is 25, sizeY is 20, tileSize is 32(whatever you are wanting your texture/tile dimension to be), and scaledSize is mapScale * tileSize:
void Map::loadMap(std::string path, int sizeX, int sizeY)
{
char c;
std::fstream mapFile;
mapFile.open(path);
int srcX, srcY;
for (int y = 0; y < sizeY; y++)
{
for (int x = 0; x < sizeX; x++)
{
// Get tile to create
mapFile.get(c);
srcY = atoi(&c) * tileSize;
mapFile.get(c);
srcX = atoi(&c) * tileSize;
// tileSize and mapScale are used now as opposed to passing in
// hardcoded numbers like before.
addTile(srcX, srcY, x * scaledSize, y * scaledSize);
// Ignore comma
mapFile.ignore();
}
}
Hope this helps in your gamedev journey! I am still figuring out as I go but if there are any questions I can answer or any way I can help with your game, I will do my best to try! Let me know.
Cheers,
Bearcat
thank you@@bearcatmakesgames, this was really helpful, what if we team up? i think i can learn from you and if you teach it will only benefit you, let me know, thanks