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

Author Topic: Unable to load tiledmap box2d object using sfml-tmxloader  (Read 1414 times)

0 Members and 1 Guest are viewing this topic.

sun

  • Newbie
  • *
  • Posts: 9
    • View Profile
Unable to load tiledmap box2d object using sfml-tmxloader
« on: September 10, 2014, 10:41:38 pm »
Hi,

I've been hacking together a simply game prototype using various technologies in an aim to build a quick game. I've started to integrate tiled maps in my game by using sfml-tmxloader to load my map and my static box2d objects. Unfortunately, I'm having odd problems loading my static box2d object via sfml-tmxloader. The problem is that I am unable to actually create box2d object via the tmx::BodyCreator::Add function anywhere else but my main function.

Here's how I load maps and static bodies through my main function:
https://github.com/SundeepK/Clone/blob/wip/add_tmx_loading/src/main.cpp#L37

And here's how I load it in my game class:
https://github.com/SundeepK/Clone/blob/wip/add_tmx_loading/src/Game.cpp#L14

My code is slightly hacky and messy since I've been trying for hours to find out why I am unable to load box2d object from the tmx::BodyCreator::Add anywhere else but my main function (before my game class is actually created). I don't know if my game class is some how altering my box2d world, but I can create box2d manually without using tmx::BodyCreator::Add and they show fine. I much rather avoid having to re-write the code to create box2d object because its pretty much free in tmx::BodyCreator. A second pair of eyes would help me greatly! Thanks.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
AW: Unable to load tiledmap box2d object using sfml-tmxloader
« Reply #1 on: September 13, 2014, 05:18:14 pm »
Please create a minimal and complete example.
From your text it's not fully clear to me, what does work and what doesn't.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

sun

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Unable to load tiledmap box2d object using sfml-tmxloader
« Reply #2 on: September 16, 2014, 11:12:29 pm »
So I fixed the problem a while back and forgot to post back, but to fix the problem I stored a pointer to my b2world object. Which I believe was not working previously (maybe you can confirm my understanding)  because I was passing by reference and then using the copy constructor to copy over my b2world to this other class, which was incorrect. For example:

LoadMap::LoadMap(b2world& box2dWorld) : m_world(box2dWorld){
}

So I switched to using a unique_ptr and will probably use pointers for such objects.

 

anything