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)

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135`` `````` 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.