SFML community forums

Help => Graphics => Topic started by: 5gum on November 19, 2013, 12:40:18 pm

Title: setTextureRect - other direction
Post by: 5gum on November 19, 2013, 12:40:18 pm
Hey,
I'm a beginner in SFML so please don't be too strict.

I painted a simple rect (Size:20*60px) and included it in my program.
Now I want that the y-position of the rect gets smaller every frame (Like a loading bar).

I tried it with

rect_timer = 0;

while(window.isOpen())
{
rect_timer += 0.1;
rect.setTextureRect(sf::IntRect(0,rect_timer,20,60-rect_timer));
}
 

But the result was, that my rect moves in the wrong direction, so the lowest part dissapeared at first but I want that the toppest part dissapeares at first.

How can I do that?

Thanks, 5gum
Title: Re: setTextureRect - other direction
Post by: fallahn on November 19, 2013, 01:02:39 pm
try moving the top of the texture rect:

int amount = 60 - rect_timer;
rect.setTextureRect(sf::IntRect(0, 60 - amount, 20, amount));
 

it's also good practice to get rid of all those magic numbers, perhaps with some const values
Title: Re: setTextureRect - other direction
Post by: 5gum on November 19, 2013, 01:07:38 pm
If I run that there's the same result...
Title: Re: setTextureRect - other direction
Post by: 5gum on November 19, 2013, 01:16:07 pm
I solved it ;D

My solution was, that I moved the Origin of the rect in the middle then I roate it 180° and now it works ^^

But thanks