SFML community forums
Help => Graphics => Topic started by: DuCT 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.
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]
-
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: )
-
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.
-
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 ?
-
Alright, now I get what your saying! I'll try fiddling with it some more.
EDIT: SOLVED. Thanks for the help Hiura!