Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


SFML - Screen Scrolling


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 mypel16000   Members   -  Reputation: 46

Like
0Likes
Like

Posted 30 January 2013 - 03:02 PM

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?

 



Sponsor:

#2 Yourself   Crossbones+   -  Reputation: 1188

Like
2Likes
Like

Posted 30 January 2013 - 04:24 PM

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)



#3 Servant of the Lord   Crossbones+   -  Reputation: 20974

Like
2Likes
Like

Posted 30 January 2013 - 05:08 PM

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.


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#4 mypel16000   Members   -  Reputation: 46

Like
0Likes
Like

Posted 31 January 2013 - 12:54 PM

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?



#5 Servant of the Lord   Crossbones+   -  Reputation: 20974

Like
3Likes
Like

Posted 31 January 2013 - 01:26 PM

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.


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#6 mypel16000   Members   -  Reputation: 46

Like
0Likes
Like

Posted 31 January 2013 - 02:10 PM

Thank you servant of the lord, very useful






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS