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

Author Topic: setTextureRect - other direction  (Read 1622 times)

0 Members and 1 Guest are viewing this topic.

5gum

  • Newbie
  • *
  • Posts: 27
    • View Profile
setTextureRect - other direction
« 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

fallahn

  • Sr. Member
  • ****
  • Posts: 492
  • Buns.
    • View Profile
    • Trederia
Re: setTextureRect - other direction
« Reply #1 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

5gum

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: setTextureRect - other direction
« Reply #2 on: November 19, 2013, 01:07:38 pm »
If I run that there's the same result...

5gum

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: setTextureRect - other direction
« Reply #3 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