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

Author Topic: scale and resolution question  (Read 6201 times)

0 Members and 1 Guest are viewing this topic.

GAMINGBACON97

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
scale and resolution question
« on: December 15, 2015, 06:16:44 am »
So, I have made a button class where my "button" has dimensions and if the mouse is clicked within those dimensions then it activates it, but each button has its own sprite and when I change the resolution I think it will break because I need all the sprites to stay the same size relative to the resolution of the window and I need some way to change the dimensions for each button so they stay with the dimensions of the sprites texture when the window resolution is changed,  I'm very confused
if you need any snippets of my code please just ask, but I dont even know what I should post because im just plum stuck.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10820
    • View Profile
    • development blog
    • Email
scale and resolution question
« Reply #1 on: December 15, 2015, 08:44:38 am »
Sounds like you need to adapt the view to the new window size. Check out the view tutorial.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Brax

  • Newbie
  • *
  • Posts: 39
  • Wannabe C++ Game Developer
    • View Profile
Re: scale and resolution question
« Reply #2 on: December 15, 2015, 12:28:21 pm »
I don't quite understand what you want to do.
As far as I can guess, you want to make the buttons be the same dimensions regardless of the resolution (i.e. to occupy the same space on the screen when resolution is 800x600 or 1280x1024) and you fear that by changing resolution, it will going to mess up the sprites dimensions (or texture rect) inside buttons.
I will assume that this is what you wanted to say.  ;D
If it wasn't, then try again with explaining your problem, preferably with some minimal code.

Quote
but each button has its own sprite and when I change the resolution I think it will break because I need all the sprites to stay the same size relative to the resolution of the window

When you set a texture rect to your sprite, it should remain the same until you explicitly demand to be changed. The texture rect of sprite also represents it's dimensions. The only other way to change dimensions without changing the texture rect is to call "scale" or "setScale" functions.

Therefore, changing resolutions shouldn't change the texture rect of a sprite.
But when you change resolutions without changing the dimensions of objects, then they will appear bigger or smaller, in regard of resolution's size.

In order to make object scale with the resolution, you need to use sf::View and keep the old view when you change resolutions.
This is the simplest aproach, do this only when you are recreating windows (usually when they are in fullscreen).

// First create a window:
sf::RenderWindow win(sf::VideoMode(1024,768)), "Bacon", sf::Style::Fullscreen);
// then make a view using the current size of the window:
sf::View view;
view.setSize(win.getSize());
win.setView(view);

// Sometime later, you recreate the window in new resolution...

win.create(sf::VideoMode(800,600)), "Bacon", sf::Style::Fullscreen);
// But now you don't reset the view size, but merely applying the old size onto the new window.
win.setView(view);
// And now the contents of the program will be resized to fit the screen.
 

Bear in mind that this is default behavior when you resize the window with your mouse. But you can't resize when in fullscreen: you need to recreate the window.

Hope it helps. :)

 

anything