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

Author Topic: Drawing things on viewport  (Read 2550 times)

0 Members and 1 Guest are viewing this topic.

N_K

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Drawing things on viewport
« on: September 18, 2012, 06:28:54 am »
Hi all,

Is there a way to draw text/sprites onto an sf::View? I use the view as a camera, instead of scrolling the game map, I move the viewport. But when I try to display some text, it will be drawn on the map, not on the viewport, and it will go out of sight when I move the camera. Or do I have to transform the text element(s) at the same speed and in the same direction as the viewport itself?

thePyro_13

  • Full Member
  • ***
  • Posts: 156
    • View Profile
Re: Drawing things on viewport
« Reply #1 on: September 18, 2012, 06:54:34 am »
Use a second view which remains stationary to draw your UI.

N_K

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: Drawing things on viewport
« Reply #2 on: September 19, 2012, 03:59:04 am »
Thanks, although I've gone a different way, I've found out that this is explained in View.hpp: set up the camera, draw the things that are supposed to be observed through the camera, then use renderWindow.setView(renderWindow.getDefaultView()) to return to the default view, then draw the things that are supposed to be drawn on the screen.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Drawing things on viewport
« Reply #3 on: September 19, 2012, 08:36:09 am »
This is the same as thePyro_13 suggested, you use a second view that is stationary, in your case the default view. ;)
Keep in mind that if you resize the window the code might 'break', since the dedault view doesn't change with the window size.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything