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

Author Topic: [SOLVED] Scrolling a bar.  (Read 2084 times)

0 Members and 1 Guest are viewing this topic.

DuCT

  • Newbie
  • *
  • Posts: 7
    • View Profile
[SOLVED] Scrolling a bar.
« on: January 28, 2011, 10:31:26 pm »
Hello everybody, I come with a simple question. I have a sprite that I want to scroll down to a certain part of the screen, and then stop. My problem is, that when I press the key to trigger the scrolling, it only does the action once. Here is the relevant code.

Code: [Select]
int moveBar(sf::Shape &Bar, sf::Clock &clockMovement, float &yRatio, float &mDelay, int &i)
{
while ( i != (yRatio/10) && (clockMovement.GetElapsedTime() > mDelay))
{
Bar.Move(0, 1);
i++;
clockMovement.Reset();
}
}


[/code]

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
[SOLVED] Scrolling a bar.
« Reply #1 on: January 29, 2011, 12:43:09 am »
The first time i is not yRation / 10 AND lockMovement.GetElapsedTime() is bigger than mDelay but the second time your while "loop" clockMovement.GetElapsedTime() is 0 (more or less) so your while end.

You may want to do this without any loop (only one move function call) – (integer) division may help you then. (I let you think about it.  :wink: )
SFML / OS X developer

DuCT

  • Newbie
  • *
  • Posts: 7
    • View Profile
[SOLVED] Scrolling a bar.
« Reply #2 on: January 29, 2011, 02:49:03 am »
I get what you're saying in the first sentance, but your second sentance just confuses me. I get that you suggest that I should just have the Bar.Move, but after that I can no longer follow.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
[SOLVED] Scrolling a bar.
« Reply #3 on: January 29, 2011, 11:12:41 am »
Well sometimes I'm very bad at giving hints, forget the last part. '^^

My point was that having a loop to move something is generally bad. We prefer to be able to compute the next position of an object in "one step" (with a math formula for example).

So here how could you achieve that ?
SFML / OS X developer

DuCT

  • Newbie
  • *
  • Posts: 7
    • View Profile
[SOLVED] Scrolling a bar.
« Reply #4 on: January 29, 2011, 04:40:00 pm »
Alright, now I get what your saying! I'll try fiddling with it some more.

EDIT: SOLVED. Thanks for the help Hiura!

 

anything