SFML community forums

Help => General => Topic started by: NBeeby on December 31, 2017, 12:42:54 pm

Title: SFML and Box2D Issue
Post by: NBeeby 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?

Title: Re: SFML and Box2D Issue
Post by: eXpl0it3r 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
Title: Re: SFML and Box2D Issue
Post by: NBeeby 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


Title: Re: SFML and Box2D Issue
Post by: eXpl0it3r 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?