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

Author Topic: A question about scrolling the view in SFML Graphics  (Read 1150 times)

0 Members and 1 Guest are viewing this topic.

CrowbarJones

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
A question about scrolling the view in SFML Graphics
« on: March 22, 2023, 07:30:29 am »
According to the tutorials, to use a view we must call a setView function before drawing. The problem is that I have a big game map which is much bigger than the window; I use the view to display a part of the map on the window, but I want to show a different part of the map when the player scrolls the mouse wheel. So I need to change the view, but to do that, I need to call setView again and draw everything again. Everything here is a very very big map, so the window display them with completely delay and no smooth. Is there any other (and more useful) way to change the view?
Thanks!
« Last Edit: March 22, 2023, 09:04:10 am by CrowbarJones »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: A question about scrolling the view in SFML Graphics
« Reply #1 on: March 22, 2023, 05:22:03 pm »
If you want to display the same content twice, you have to ... draw the same content twice. :D

You can use a RenderTexture to "cache" the output, so instead of drawing the whole scene twice, you'd just have to draw a sprite twice.
If your rendering becomes too slow, you may also consider applying your own culling for the parts that are currently not visible on the screen.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything