SFML community forums

General => SFML projects => Topic started by: Viperz012 on February 11, 2015, 03:42:00 am

Title: fallahn sfml-tmxloader
Post by: Viperz012 on February 11, 2015, 03:42:00 am
I was curious if anyone has used this and if so would anyone want to post example of collision control? Even source code from project I could examine we be so helpful!
Title: Re: fallahn sfml-tmxloader
Post by: Gamachara on February 11, 2015, 04:18:54 am
Obviously fallahn will know it better than anyone but I have used it a little bit. As far as I know the loader itself doesn't really do anything for collision. I'm sure there are ways to code generating the collision boxes in an efficient way but I have always opted to manually put in collision rectangles as a "bounds" layer in the TMX.

(http://i.snag.gy/9ZKKQ.jpg)

I'm just copying and pasting pieces but I gathered a vector of collision boxes like this.

Quote
std::vector<sf::FloatRect> mapBounds;
tmx::MapLoader map("maps\\");
std::vector<tmx::MapLayer> mapLayers;
sf::Vector2u mapSize;

void Scene::loadmap(std::string mapName)
{   
   map.Load(mapName);

   mapBounds.empty();
   mapLayers = map.GetLayers();
   mapSize = map.GetMapSize();

   for (const tmx::MapLayer layer : mapLayers)
   {
      if (layer.name == "Bounds")
      {
         for (const tmx::MapObject& mapObject : layer.objects)
         {
            mapBounds.push_back(mapObject.GetAABB());
         }
      }
Title: Re: fallahn sfml-tmxloader
Post by: fallahn on February 11, 2015, 10:37:06 am
There's this (http://trederia.blogspot.co.uk/2013/10/collision-detection-with-tiled-maps.html), this (http://trederia.blogspot.co.uk/2013/12/tiled-map-loader-for-sfml-and-box2d.html) and, to a lesser extent, this (http://trederia.blogspot.co.uk/2013/06/optimising-collision-testing.html). There are examples for all three included in the repository.