Closed Tonire closed 8 years ago
A couple of things I notice: mainly this
tmx::MapLayer res = tmx::MapLayer(ml.GetLayers().at(num));
is going to create a copy of a layer and is probably not going to perform brilliantly compared to fetching a reference. Even worse it gets copied again when it's returned from your function. gcc 4.8 should support range-based loops so:
const MapLayer& getLayer(const std::string& name)
{
const auto& layers = ml.getLayers();
for(const auto& l : layers)
{
if(l.name == name) return l;
}
return layers[0];
}
might serve you better. On the other hand (although I admit I can't remember off the top of my head) the map loader does some behind the scenes stuff with culling and setting views to optimise layer drawing. In which case drawing the layer directly won't work and you'll need something like
ml.draw(window, index, false);
to draw a specific layer. In this case your getLayer() function should just return the index of the layer that contains the name you want, or 0 if it does not exist.
ml.draw(window, getLayer("myLayer"), false);
Thank you very much! Performance problems aside, I can't call ml->Draw() because the first parameter is a RenderTarget. I think I'm missing something here, I can't pass it my sf::RenderWindow :/
Anyways, I made It to work implementing
MapLoater::Draw(sf::RenderWindow rw, MapLayer ml, bool debug = false);
myself and It is working nice!
Thank you again <3
No problem. From what it looks like in your sample code your window is a pointer, so this should work:
ml.draw(*window, index, false);
as RenderWindow inherits RenderTarget.
Hi! I'm trying to render each layer individually. For so I made this little function:
So im calling it like this:
m->mWindow->draw(GetLayer("Capa 1"));
And the result is a little square at the top of the window
When the layer is much bigger
I don't know if GetLayers() is supposed to work like this or not. Maybe is a bug?
Thank you so much!
PS: Im using gcc 4.8 on Windows, if that helps...