Giter Site home page Giter Site logo

Comments (6)

fallahn avatar fallahn commented on June 21, 2024

Hi, as you 've closed this I'll assume you found a solution - there are a couple of links you can check out though:
http://trederia.blogspot.co.uk/2013/10/collision-detection-with-tiled-maps.html
http://trederia.blogspot.co.uk/2016/02/2d-physics-101-pong.html

Alternatively my SFML frame work xygine has built in tmx/collision support (check the 2D tilemap demo in the included example)

from sfml-tmxloader.

Rikora avatar Rikora commented on June 21, 2024

Yeah, I solved it and thanks for the links 👍 But if you solve one problem, another one pops up, hehe...

So, right now it's detecting colission with the player sprite and the platforms, so I can jump on them and everything works fine that way. But, as it seems, the colission is constantly checking all of the objects in the layer, something which could be fixed by using a quadtree, which you mentioned in your blog and on the homepage of this repository.

So I simply did:

ml.UpdateQuadTree(sf::FloatRect(0.f, 0.f, 800.f, 600.f));
 std::vector<tmx::MapObject*> objects = ml.QueryQuadTree(player.getPlayer().getGlobalBounds());

and then I check for colission with the objects in the layer. But it seems like it's not working as expected as the debug text prints out a mix of 'true' (if colission occur) and 'false' (colission didn't occur), when it should printout only 'true' (if I'm intersecting with a platform) as I should only be checking with each platform at a time.

//Check for colission
        for (auto& layer : layers)
        {
            if (layer.type == tmx::ObjectGroup)
            {
                for (auto& obj : layer.objects)
                {
                    if (layer.name == "Collide")
                    {
                        if (obj.GetAABB().intersects(player.getPlayer().getGlobalBounds()))
                        {
                            std::cout << "True" << std::endl;
                            whileJump = false;
                            player.accelarationValue = 0;
                        }

                        else
                            std::cout << "False" << std::endl;
                    }
                }
            }
        }

Do you have any ideas? @fallahn

from sfml-tmxloader.

fallahn avatar fallahn commented on June 21, 2024

No, that sound right. If a layer or quad tree query returns 3 platforms and you only intersect one, then the output would be

true
false
false

or similar, as you're only colliding with one of the 3 platforms. Try also outputting the layer object count, and see if it matches up with the number of true/false statements in the console

from sfml-tmxloader.

Rikora avatar Rikora commented on June 21, 2024

Hmm, oh that sounds quite right, yeah. But still, I'm having an issue how to make the player unable to continue walking when he's actually in midair, which is actually why I wanted it to only print 'true' when I was intersecting with one platform. Because if it would, I could have a boolean in there which would turn true if I was intersecting and then false if I wouldn't intersect. Then I could use this boolean to restrict the player movement and simply let the player fall free if not on the platform. But as it is now, this boolean would switch from true to false even if I was on one single platform, making this approach useless. What would be the recommended approach? :) @fallahn

from sfml-tmxloader.

fallahn avatar fallahn commented on June 21, 2024

This might help :)

from sfml-tmxloader.

Rikora avatar Rikora commented on June 21, 2024

Yep, I have to look into the art of game design a bit more. Thanks for the help anyways and the effort you put into the library.

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.