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

Author Topic: A couple of questions about sprites  (Read 1355 times)

0 Members and 1 Guest are viewing this topic.

carton83

  • Newbie
  • *
  • Posts: 38
    • View Profile
A couple of questions about sprites
« on: January 10, 2014, 07:26:24 am »
How do I scale my sprites up or down if the window gets resized without affecting the aspect ratio of the sprite?  I'm assuming that I would base the size of all the sprites on the height of the window.

I'm not entirely sure how to ask this question.  Lets say that I have a window and it's aspect ratio is 1:1. If I were to stretch the window so it's ratio was now 2:1 how would I go about changing the aspect ratio of the camera?  I'd just pass on the new window dimensions to the setSize function from the view class, right?

How would I keep everything in the same, relative position if the window was resized to an overall smaller or larger size? This one just popped into my head and I have yet to thought of a possible solution.


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11035
    • View Profile
    • development blog
    • Email
Re: A couple of questions about sprites
« Reply #1 on: January 10, 2014, 09:04:39 am »
There are essentially three options you can go with when resizing the window:
  • Don't do anything and let it get scaled, while the aspect ratio is not being preserved.
  • Adjust the the view to keep the ratio intact and fill the unused space either with black bars or some decorative bits.
  • Give the player more content for more screen space.

If the game allows it, the third option should always be considered. If the game uses a fixed game space, option 1 or 2 are good.

So if you want to keep the aspect ration, you'll have to adjust the view correctly - see the tutorial on how to utilize the view. The math behind it, is very simple. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

carton83

  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: A couple of questions about sprites
« Reply #2 on: January 10, 2014, 09:33:31 am »
I'd like to preserve the aspect ratio (it looks ugly and very unprofessional to do otherwise; I feel that one should always strive for at least professional quality work) and I certainly want to do option three as the location never changes in my game.

That tutorial looks like it covers my needs and will certainly dive into it.  Thanks!