Jump to content
  • Advertisement
Sign in to follow this  
mypel16000

SFML - Screen Scrolling

This topic is 2085 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!