Sign in to follow this  
mypel16000

SFML - Screen Scrolling

Recommended Posts

Hi, I am implementing screen scrolling on my game (I imagine it will be easy, just using sf::Sprite::useSubRect()), but this isn't the main problem. My game has zombies that have a position x, y (relative to the window) and it has different sprites located in different locations. If I wanted my player to move around a big 2000x2000 map, how would I know what the position of my stuff is (relative to the top corner of the big 2000px map. ) And adjust my code which now uses co-ordinates in the screen?

 

Share this post


Link to post
Share on other sites

make your objects (zombies, sprites, ..) relative to the upper-left corner of the current view of the map (not the origin).
so, if you start looking at the map with a 150px offset, the x-position of an object is (m_ObjectPosition.x - 150)

Share this post


Link to post
Share on other sites

Two ways: 

1) Calculate camera position yourself, and the entities on the camera.

PosOnScreen = (PosInWorld - CameraPos);

 

2) Draw everything using absolute positions, and use SFML's sf::View to move the camera.

 

Whichever method you use, if you are drawing alot of objects, make sure you filter out which objects are actually visible on-screen before drawing them.

Share this post


Link to post
Share on other sites

How do I use absolute position and SFML::View? Got a tutorial or some instructions?

 

I would also like to add my a star algorithm ( if someone gives me some help with it ) and functions that take x and y values.... what do I do?

Share this post


Link to post
Share on other sites

Whatever algorithms you use have no bearing on your camera. All that matters is: A) Where in the world your objects are, and B) What portion of the world is visible. From that you calculate where on the screen the objects need to show up in.

 

As for sf::View, here's a tutorial on it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this