Giter Site home page Giter Site logo

Comments (4)

fallahn avatar fallahn commented on July 23, 2024

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);

from sfml-tmxloader.

Tonire avatar Tonire commented on July 23, 2024

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 :/

from sfml-tmxloader.

Tonire avatar Tonire commented on July 23, 2024

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

from sfml-tmxloader.

fallahn avatar fallahn commented on July 23, 2024

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.

from sfml-tmxloader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.