fallahn / sfml-tmxloader

SFML 2.x based tmx tilemap parser for files created with Tiled tile map editor
106 stars 35 forks source link

Collision issues #61

Closed Elit3d closed 8 years ago

Elit3d commented 8 years ago

Not exactly 100% on the collision, so far I have this but it isn't recognizing my player inside of the collision for some reason. Here is my code:

http://pastebin.com/6F4kjEJX

jdmarsh commented 8 years ago

If you're using SetPosition, it calls Move which edits the polypoints and causes collision issues, there is a bug for it here: https://github.com/fallahn/sfml-tmxloader/issues/21

Elit3d commented 8 years ago

is there a way around this? been trying to get my player to collide with the walls but gave up as it wasn't recognizing it

jdmarsh commented 8 years ago

You can comment out the lines where the polypoints are changed in MapObject::Move but even after I did this I was getting some different issues and I didn't want to waste lots of time debugging it.

I went the route of converting each MapObject into an sfml convex shape and wrapping it in my own class. You'll have to copy the MapObject::intersects and MapObject::contains methods to do collision with the convex shapes.

fallahn commented 8 years ago

This is basically down to a badly designed MapObject class on my part. I'm aware of this and plan to rewrite it using the sf::Transformable class. As this will be likely an API breaking change it will be part of version 2 of the map loader (although I can't offer any estimation on when it's done, I only work on this as time allows). Version 2 can always be previewed via the 'next' branch of the repository (and already has many improvements) if you want to track its progress. For a work around in its current state, although it's a little more effort, the box2D utilities do correctly parse map objects, so the box2D collision detection system can be used. Box2D doesn't force you to use the physics part if you only wish to detect collisions - they can be handled by your own callbacks if you'd prefer (check out the box2D docs for this).

Elit3d commented 8 years ago

So I wouldn't need box2d in order to do this method?

fallahn commented 8 years ago

You still need to link to box2D. Using the functions found in tmx2box2d.cpp you can then convert the map objects to box2D objects. Afterwards you can either let box2D use its physics, or you can supply callbacks to box2D to handle your own collisions.

fallahn commented 8 years ago

I've pushed a potential fix for this to the 'next' branch, if anyone would like to try it and offer feedback / pull requests. I'll close this particular issue and point to #21 for further discussion