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

Author Topic: can i resize my image not sprite? Reason is checking getPixel after resize  (Read 1589 times)

0 Members and 1 Guest are viewing this topic.

battosaijenkins

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
I've been searching for days on google and reddit and other forums but I can't seem to figure it out. And if there is already a solution for this then I apologize for duplicates...

What I want is to test my mouse point on getPixel() for rgba values but that can only be done with sf::Image which I understand.

However, after I setScale with sprite I realize that the resize doesn't apply to the original image. Is there a way to resize the sf::Image somehow so that the scale updates as well?

For example, i have a star image that's width 50 and height 48 with a transparent background as star.png. I can set a sf::Texture and then sf::Sprite sprite(starImage) then setScale(2, 2) which doubles; but when I try to getPixel() for the image from sf::Image image = starImage.copyToImage() I get the original dimensions and not the doubled.

I feel like I'm missing something or is this not possible? I suppose I can just resize the original star png file and all the other png files ahead of time manually in photoshop to fit the window but is there an easier way? Thanks in advance.
« Last Edit: January 09, 2020, 11:06:11 pm by battosaijenkins »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
A generic solution is to take the inverse of the transform of the sprite, and apply it to your cursor position. This way you get the point to test in sprite local coordinates, which always match the texture's coordinate system.

If you only scale your sprite, then you can simplify this and just divide mouse coordinates by the scale factor.

Scaling the image itself would make no sense, this is just a computational issue, all you need is a formula ;)
Laurent Gomila - SFML developer

battosaijenkins

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
If you only scale your sprite, then you can simplify this and just divide mouse coordinates by the scale factor.

Oh man, thank you so much Laurent this worked perfectly! Why couldn't I figure that out damn my feeble brain, you are a genius! Now I don't need to spend hours doing mind numbing photoshop resizes phew!!! :D