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

Author Topic: How to make sprite scale with the window?  (Read 4854 times)

0 Members and 1 Guest are viewing this topic.

Jgwman

  • Newbie
  • *
  • Posts: 3
    • View Profile
How to make sprite scale with the window?
« on: February 17, 2013, 10:59:13 pm »
Hello, I am somewhat new to SFML and did not know how (if it is possible) to scale a sprite to the window. For example, my render window uses
sf::VideoMode::getDesktopMode()
for the render window, and I have a main menu sprite which I would like to be the same size as the window. What is the best way to go about doing this? I have searched and could not find an answer. I am using the most recent nightly build of SFML 2.0 for MinGW 4.71. Thanks in advance.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: How to make sprite scale with the window?
« Reply #1 on: February 17, 2013, 11:23:30 pm »
If you don't scale anything, your sprite will have the size of the texture. So now that you know, the wanted size and the current size you can easily calculate the scale factor (wanteSize/currentSize).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jgwman

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: How to make sprite scale with the window?
« Reply #2 on: February 18, 2013, 02:15:39 am »
Sorry, I guess I didn't phrase that well - I want to know how to get the screen resolution to use (as in, I have the current, but not the wanted). The only way I know to get the resolution is the getDesktopMode function in my previous post, but how would I get two floats for the scale() function from this? How do I just get monitor width/height?
float scaleFactorX = (desktop resolution width)/ 1600;
float scaleFactorY  = (desktop resolution height)/ 900;
menu.scale(scaleFactorX, scaleFactorY);
How do I get the width and height?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
AW: How to make sprite scale with the window?
« Reply #3 on: February 18, 2013, 02:38:38 am »
By looking at the documentation. ;)
The video modes hace public attributes width and height. And for the current window size you can use the the getSize function.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jgwman

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: How to make sprite scale with the window?
« Reply #4 on: February 18, 2013, 02:59:20 am »
Sorry, I looked and really didn't see that the first time... I may have been looking at the 1.6 documentation,  also on my computer, by accident. Thanks, and sorry about that!

 

anything