Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: fallahn sfml-tmxloader  (Read 2893 times)

0 Members and 1 Guest are viewing this topic.

Viperz012

  • Newbie
  • *
  • Posts: 2
    • View Profile
fallahn sfml-tmxloader
« 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!
« Last Edit: February 11, 2015, 03:54:39 am by Viperz012 »

Gamachara

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • My game dev blog
Re: fallahn sfml-tmxloader
« Reply #1 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.



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

fallahn

  • Sr. Member
  • ****
  • Posts: 492
  • Buns.
    • View Profile
    • Trederia
Re: fallahn sfml-tmxloader
« Reply #2 on: February 11, 2015, 10:37:06 am »
There's this, this and, to a lesser extent, this. There are examples for all three included in the repository.

 

anything