efficient way to draw tiles

Jun 2, 2013 at 5:31pm
Hi, I'm wondering if there is a better way to draw tiles with a transition from grass to sand. So that the tiles blend in together.

My map file that i use looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
ssssssssssssssssssssssssssss
s..........................s
s.ssssssssss.......955558..s
s.s........s.......311112..s
s.s........s.......311112..s
s.s..55555555555555111112..s
s.s..31164444447164111112..s
s.s..3112..s...312.744446..s
s.s..3112..s...312.........s
s.s..3112..s...312.........s
s.s..3112..s...312.....32..s
s.s..4444..s...312.....32..s
s.s........s...312.....32..s
s.ssssssssss...3112....32..s
s..............31112...32..s
s..............311112......s
s...111111.....311112......s
s...111111.....31112.......s
s...111111.....3112........s
s..............312.........s
s..............312.........s
ssssssssssssssssssssssssssss

The "s" represents a stone tile the "." a grass tile.
The 1-9 are different transitions from grass to sand. For example the 3 is a grass to sand while the 2 is sand to grass. I use different numbers for every transition and I'm looking for a less teasingly way of doing this. it would ease a whole lot.


if it helps I'm currently loading my file like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
std::ifstream openfile(filename);
    if(openfile.is_open())
    {
        openfile >> mapSizeX >> mapSizeY;
        std::getline(openfile, line);
        while(!openfile.eof())
        {
            std::getline(openfile, line);
            coord.push_back(new std::string(line));
        }
    }else{
        std::cout << "couldn't load the requested file: " << filename << std::endl;
    }


And then i initialize the tiles like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
initTile(grass, '.', true,32, 32);

    initTile(sand, '1', true, 96, 0);

    initTile(grass2sandL, '2', true, 0, 32);
    initTile(grass2sandR, '3', true, 64, 32);
    initTile(grass2sandU, '4', true, 32, 0);
    initTile(grass2sandD, '5', true, 32, 64);
    initTile(grass2sandUL, '6', true, 0, 0);
    initTile(grass2sandUR, '7', true, 64, 0);
    initTile(grass2sandDL, '8', true, 0, 64);
    initTile(grass2sandDR, '9', true, 64, 64);

    initTile(stone, 's', true, 128, 0);

The first parameter in the initTile function is a enum, the second is which symbol it represents and the third, the Boolean, really doesn't do anything yet. Lastly the two last parameter is the coordinates of the texture i want to use in my tileset image. As you can see I init 8 different grass2sand and it just makes so complicated.
Jun 2, 2013 at 6:07pm
I dont get it, grass to sand? sand to grass? what are you trying to achieve?

is this a console application? if soo you should have a two dimensional grid of chars like this one.

char grid[70][30]; //or something similar

then you will have a printGrid() function that simply prints the whole grid onto the screen. lastly you can manipulate it with whatever technology you know.
Jun 2, 2013 at 7:00pm
Sorry if I made myself unclear. for example in this tileset:
http://img205.imageshack.us/img205/6130/transwoodlanddesertex7.png

you'll notice that there are some tiles that are not only one element. There is a transition between them. The first tile in the image is only one element but the one left from it is a mixture of two different elements. In my case i want a transition from grass to sand. The idea behind this is to make a smooth transition between different tiles.

I'm wondering if there is a simpler way of drawing them. As you can see in my map it makes it very messy with all the different numbers and I'm worried that if I want too add more tile transitions it would make my map file unbearable to construct and read.

I hope this helped understand a little better.
Jun 2, 2013 at 7:56pm
ahhh, your trying to make a background generator. I tried to do that once, failed epicly though. spend like a week I remember.

you have a good idea of transitioning from grass to sand. if I were you (or me 2 years ago) I would make everything pure grass tiles, and then have a function that blits sand on each tile as appropriate to the transition level.

the function would blit the sand randomly across the tile.

lets say that adding trasition lvl 5 sand onto a grass tile your function would first decide if it wants to add 5 small sand ponds, or 2 medium sand ponds and 1 small, 1 large sand pond and 1 medium, or 1 large and 2 small.
small sand pond = 1 transition level
medium sand pond = 2 transition level
large sand pond = 3 transition level

you should have a sprite sheet for each pond size.

then for each pond the function chooses a random x,y coordinate and blits that pond into the tile at that location.

the more types of ponds you make, the more random it will appear to be.

Try using sprite sheets for this type of task, if you arnt already.
Topic archived. No new replies allowed.