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

Author Topic: SFML and Box2D Issue  (Read 1270 times)

0 Members and 1 Guest are viewing this topic.

NBeeby

  • Newbie
  • *
  • Posts: 2
    • View Profile
SFML and Box2D Issue
« on: December 31, 2017, 12:42:54 pm »
Hi, I'm creating an RPG in C++ with SFML which uses a view which is 800 x 600 and the rest of the window is several thousand pixels. I'm wanting to add basic collision detection and I was told to use Box2D.
My problem is, when implementing Box2D and trying to create a body, it'll only draw to the view, and as my player scrolls, the box wont go out of view. Is there any way to get a body to draw to the window and leave the view when out of view?


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: SFML and Box2D Issue
« Reply #1 on: December 31, 2017, 01:05:34 pm »
Not sure I understood you correctly, but with the sf::View viewport you can define what's visible and what isn't.

See the official tutorial: https://www.sfml-dev.org/tutorials/2.4/graphics-view.php
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

NBeeby

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: SFML and Box2D Issue
« Reply #2 on: December 31, 2017, 01:33:27 pm »
I created the sprites already and positioned them on the map, however I want to set the Box2D body to the position of the objects, so that when the player moves the box2D object leaves the view.

However when I create the box2D object it stays in it's position in the view, rather than going off the view with the other sprites.

I'm unsure on how to set the Box2D object position on the map and not the view



eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: SFML and Box2D Issue
« Reply #3 on: December 31, 2017, 02:18:27 pm »
I don't know either from the top of my head, but you're not the first one to use Box2D with SFML, as such a simple search will reveal example code which may help you further.

You also need to be more specific with your wording. What sprite are you referring to? What position do you mean? What is the view? What does "leaving the view" mean to you? How do you know the Box2D body is staying in the view given that you can't see it?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/