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

Author Topic: How to properly resize sf::Rectangleshape  (Read 2646 times)

0 Members and 1 Guest are viewing this topic.

Szustarol

  • Newbie
  • *
  • Posts: 19
    • View Profile
How to properly resize sf::Rectangleshape
« on: July 06, 2016, 07:42:25 pm »
Hi
I have a texture lets name it texutre one.
So texture one's resolution is 500x250
I also have a RectangleShape
I want to:
set the texture to Rectangle shape, then rotate it by 90 degrees
for example
XXXXXXXXX
XXXXXXXXX
XXXXXXXXX
to:
XXXX
XXXX
XXXX
XXXX
XXXX

thats kinda easy to do, i have a problem later

i want to set the width of already rotated Rectangleshape to 30% of the overall screen width which i something managed to do.
now the hardest part i dont know how to do (i tried every possilbe way i can think of)
i want to set the lenght (or actually the height of  already rotated element) so it keeps the proportion;
for example if texture is 500x250 the proportion is 2
so i want the lenght (height) of the shape to be 2 times longer than its width, of course these values change some texture can be 500x100, some can be 500x200
i have tried something like this
shape.setsize(texture.getsize().x/texture.getsize.()y*screenwidth*0.3, screenwidth*0.3);
but it doesnt work, im not sure why (the textures indeed show, but they are flattened)
can anyone explain why it is not working and give me a better idea?

The exact order of things being done is:
loadfile to texture
set texture to rectangleshape
set size of rectangleshape
set its origin (it has to be changed by its height because it will be rotated 90 degree and i want upper left corner be 0,0 not 0, -height)
set its position on screen (not mportant here i guess)
rotate it

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: How to properly resize sf::Rectangleshape
« Reply #1 on: July 06, 2016, 08:01:59 pm »
Quote
texture.getsize().x/texture.getsize.()y
This is integer division, which will always give you an integer whereas your ratio will most likely be a decimal number. You need to cast one of the operands to float, or move this part of the expression after screenwidth*0.3.
Laurent Gomila - SFML developer

Szustarol

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: How to properly resize sf::Rectangleshape
« Reply #2 on: July 06, 2016, 08:49:31 pm »
you mean like static_cast<texture.getsize().x>(float)?

(It works when i changed the order just asking how should i cast it)
« Last Edit: July 06, 2016, 09:01:52 pm by Szustarol »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: How to properly resize sf::Rectangleshape
« Reply #3 on: July 06, 2016, 09:52:42 pm »
I mean like static_cast<float>(texture.getsize().x).
Laurent Gomila - SFML developer