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

Author Topic: One does not simply scale an object  (Read 2617 times)

0 Members and 1 Guest are viewing this topic.

Mal1

  • Newbie
  • *
  • Posts: 18
    • View Profile
One does not simply scale an object
« on: April 18, 2013, 10:22:15 pm »
Let's get straight to the problem, I'm writing my simple project thingie, I came up with an idea to split the screen in more separate containers, it kinda works, except of vertical, wanna help me out here?
http://i.imgur.com/1pC9XeI.png is the graphical way to show you what it looks like
Counting out areas for 1
Area data - l = 533 t = 1 h = 599 w = 799
Vertical split = 399
Pushing L = 533 T = 1 W = 799 H = 400
Pushing L = 533 T = 400 W = 799 H = 799
0 L = 533 T = 1 W = 799 H = 400
1 L = 533 T = 400 W = 799 H = 799
Area L = 533 T = 1 W = 799 H = 400
Setting size at 266x399
Area L = 533 T = 400 W = 799 H = 799
Setting size at 266x399
Size = 1.70513x2.8913
Size = 1.70513x2.8913
 
The data it's using, the image is 156x138
The X scale = 1.70513, as you can read it, Y scale is = 2.8913
So... what's wrong?
Well, technically, nothing
Except that window that's on the image has 800 pixels
If the height of each image is 400, how is the second one coming out of the window?

sprite->setPosition( this->Area.left, this->Area.top );
                const sf::Texture *vectemp = sprite->getTexture();
                sf::Vector2u vec = vectemp->getSize();
                sprite->setScale(( ( this->Area.width - this->Area.left)  / vec.x ), ( ( this->Area.height - this->Area.top ) / vec.y ));
                std::cout << "Setting size at " << this->Area.width - this->Area.left << "x"
                << this->Area.height - this->Area.top << std::endl;

Ideas?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: One does not simply scale an object
« Reply #1 on: April 18, 2013, 11:07:22 pm »
To be honest, I've no idea what all those numbers should represent and I also don't want to stare at it for an hour to figure out, what exactly you're trying to communicate... ;)

I came up with an idea to split the screen in more separate containers, it kinda works, except of vertical, wanna help me out here?
Have you ever thought about using sf::View, it's very simple and you only have to scale the different views once correctly and everything else will happen automatically. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Mal1

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: One does not simply scale an object
« Reply #2 on: April 19, 2013, 07:10:46 am »
Won't sf::View affect the whole screen though? I only want to manipulate a set images of sprites by setting their position and size, the thing is that they don't show up correctly
If you'd look in the link I posted, you could see there are 2 rectangles, their size, as they give me the output, is 26something x 399
The window is 800 h, so it's not exactly working as it should, since the second object should fit in there too

foobarbaz

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: One does not simply scale an object
« Reply #3 on: April 19, 2013, 08:15:30 am »
Yes, sf::View will affect the entire screen, but you can apply a view, render all of your game sprites, then reset to the default view and render your health bars, interface, and whatnot.

Mal1

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: One does not simply scale an object
« Reply #4 on: April 19, 2013, 09:04:50 am »
Still, I don't want to use sf::View, it just won't do, I have to repeat this with too many objects at the same time, it just simply won't work
I just need a way to fix the scaling of the objects on the window without affecting the view/resetting it

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: One does not simply scale an object
« Reply #5 on: April 19, 2013, 09:09:40 am »
No a view does only affect the area that you specify to use (see the link above...).

I've looked at your link, but you've never really stated what the problem is, i.e. what you d expect to happen and what actually happens. ;)

You can use as many views as you want and render different sets of images with different views.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Mal1

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: One does not simply scale an object
« Reply #6 on: April 21, 2013, 10:08:45 pm »
I just want to scale an image to X/Y size, that's all.
Still, clearly SFML doesn't scale it properly, that's the problem

 

anything