Drawing Layer/Fringe for tile engine SDL

for some reason the code i wrote doesnt work the way i expected
it doesnt draw overlap image at all.

This is my Map and Layer class (the map contain the layers, and what i want it to do is to draw layer 1 at the bottom, and go all the way up to layer 12 at the top. Assuming that all the tiles are transparented)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135

class Layer
{
private:
	int* theLayer;
public: 
	Layer();
	void DrawLayer(int maxx, int maxy);
	void LayerEdit(int whichTile, int tileValue);
	int GetLayerTile(int whichTile);
	void GenerateLayer(int maxx, int maxy);
};

void Layer::GenerateLayer(int maxx, int maxy)
{
	theLayer = new int[maxx*maxy];
	for (int i = 0; i < (maxx*maxy); i++)
	{
		theLayer[i] = 0;
	}
}

Layer::Layer()
{
	int maxX = 10, maxY = 10;
	GenerateLayer(maxX, maxY);
}

void Layer::DrawLayer(int maxx, int maxy)
{
	SDL_Rect loc;
	loc.x = 0;
	loc.y = 0;
	for (int i = 0; i < (maxx*maxy); i++)
	{
		if(i == 0)
		{
			loc.x = 0;
		}
		else
		{
			loc.x += 32;
		}

		if((i + 1) % maxy == 0)
		{
			loc.x = 0;
			loc.y += 32;
		}

		myTile[theLayer[i]].DrawTile(loc);
	}
}

void Layer::LayerEdit(int whichTile, int tileValue)
{
	theLayer[whichTile] = tileValue;
}

int Layer::GetLayerTile(int whichTile)
{
	return theLayer[whichTile];
}


class Map
{
private:
	string Name;
	Layer myLayer[12];
	int MaxX, MaxY;
public:
	Map();
	void GenerateMap();
	void DrawMap();
	int GetMaxX();
	int GetMaxY();
	void SetCoordinate(int x, int y);
	Layer getLayer(int whichLayer);
	~Map();
};

Layer Map::getLayer(int whichLayer)
{
	return myLayer[whichLayer];
}

void Map::SetCoordinate(int x, int y)
{
	MaxX = x;
	MaxY = y;
	GenerateMap();
}

int Map::GetMaxX()
{
	return MaxX;
}

int Map::GetMaxY()
{
	return MaxY;
}

Map::~Map()
{
}

Map::Map()
{
	Name = "Blank";
	MaxX = 10;
	MaxY = 10;
	GenerateMap();
}

void Map::DrawMap()
{
	for (int i = 0; i < 12; i++)
	{
		myLayer[i].DrawLayer(MaxX, MaxY);
	}
}

void Map::GenerateMap()
{
	for (int i = 0; i < 12; i++)
	{
		myLayer[i].GenerateLayer(MaxX, MaxY);
	}
}

Map myMap[250];



assume that i setted up the data correctly, just that the drawLayer function doesnt draw over lap each other, what am i doing wrong?
I see a few problems.


The main one (which might be causing your problems) is that in DrawLayer, you specify x and y, but you don't specify a width/height. Or are you doing that in your DrawTile function?


Also, why do you have 250 maps?


The rest that I can see if just performance stuff. For example, you don't want to draw every tile of the map, you only want to draw what's going to be visible on screen. Also, you don't want to draw tiles that are fully transparent.

And, quite frankly, SDL's drawing performance kind of sucks from my experience. It's very rarely hardware accellerated because it uses really arcane drawing concepts (blitting, dirty rects), whereas modern hardware tends to be more geared towards a different style (full scene redrawing and textured polygons). 12 layers is a lot, and if you're going to get any kind of workable performance with that much drawing you're going to have to get really smart with it and only draw what's absolutely necessary.

But don't take my word for it. Do some tests for yourself and see what kind of framerate you can get with drawing 12 full layers every frame.
Last edited on
Topic archived. No new replies allowed.