1
General / Re: sf::clock not working (or maybe I am being stupid)
« on: August 16, 2012, 11:33:24 pm »
I have got stuck again, yes I am a total noob at this. So basically I want to have 2 loops going off one will be the loop for when my invader is moving left the other when it is moving right. Now my idea was that on the moving down part of each loop ie when the invader hits the side of the screen and moves down I would simply change a bool from being false to true and it would go onto the next loop, then that one at its down bit would change it back. Its not having it, the 2 errors I am getting while playing around with different things is either the sprite will go down and then continue moving the same way, ie not breaking out the loop when the bool changes, or if I force the loop to end with a break my program terminates.
Could you guys help me out again please:
Disregard all the random X's and things, I have been trying out a lot of different stuff.
Could you guys help me out again please:
while (movementloop = true){
bool x ;
if ( x = true)Invader1Sprite.Move(-2 * 0.05,0 );
if ( x = false)Invader1Sprite.Move(-2 * 0.05, 0);
float ElapsedTime = clock.GetElapsedTime();
float ElapsedTime2 = clock2.GetElapsedTime();
if (ElapsedTime >= 2.0){Invader1Sprite.SetImage(Invader2);}
if (ElapsedTime >= 4.0){Invader1Sprite.SetImage(Invader1); clock.Reset();}
if (ElapsedTime2 >= 10 ){Invader1Sprite.Move(0, 1 * 0.05); Invader1Sprite.Move(+2 * 0.05, 0);}
if (ElapsedTime2 >= 11){ clock2.Reset();movementloop = false; break;}
Window.Clear(sf::Color(0, 0, 0));
Window.Draw(Invader1Sprite);
Window.Display();}
while (movementloop2=false){
bool x ;
if ( x = true)Invader1Sprite.Move(-2 * 0.05,0 );
if ( x = false)Invader1Sprite.Move(2 * 0.05, 0);
float ElapsedTime = clock.GetElapsedTime();
float ElapsedTime2 = clock2.GetElapsedTime();
if (ElapsedTime >= 2.0){Invader1Sprite.SetImage(Invader2);}
if (ElapsedTime >= 4.0){Invader1Sprite.SetImage(Invader1); clock.Reset();}
if (ElapsedTime2 >= 10 ){x=false;Invader1Sprite.Move(0, 1 * 0.05); Invader1Sprite.Move(+2 * 0.05, 0);}
if (ElapsedTime2 >= 11){ clock2.Reset();}
Window.Clear(sf::Color(0, 0, 0));
Window.Draw(Invader1Sprite);
Window.Display();
movementloop = true;
}
}
bool x ;
if ( x = true)Invader1Sprite.Move(-2 * 0.05,0 );
if ( x = false)Invader1Sprite.Move(-2 * 0.05, 0);
float ElapsedTime = clock.GetElapsedTime();
float ElapsedTime2 = clock2.GetElapsedTime();
if (ElapsedTime >= 2.0){Invader1Sprite.SetImage(Invader2);}
if (ElapsedTime >= 4.0){Invader1Sprite.SetImage(Invader1); clock.Reset();}
if (ElapsedTime2 >= 10 ){Invader1Sprite.Move(0, 1 * 0.05); Invader1Sprite.Move(+2 * 0.05, 0);}
if (ElapsedTime2 >= 11){ clock2.Reset();movementloop = false; break;}
Window.Clear(sf::Color(0, 0, 0));
Window.Draw(Invader1Sprite);
Window.Display();}
while (movementloop2=false){
bool x ;
if ( x = true)Invader1Sprite.Move(-2 * 0.05,0 );
if ( x = false)Invader1Sprite.Move(2 * 0.05, 0);
float ElapsedTime = clock.GetElapsedTime();
float ElapsedTime2 = clock2.GetElapsedTime();
if (ElapsedTime >= 2.0){Invader1Sprite.SetImage(Invader2);}
if (ElapsedTime >= 4.0){Invader1Sprite.SetImage(Invader1); clock.Reset();}
if (ElapsedTime2 >= 10 ){x=false;Invader1Sprite.Move(0, 1 * 0.05); Invader1Sprite.Move(+2 * 0.05, 0);}
if (ElapsedTime2 >= 11){ clock2.Reset();}
Window.Clear(sf::Color(0, 0, 0));
Window.Draw(Invader1Sprite);
Window.Display();
movementloop = true;
}
}
Disregard all the random X's and things, I have been trying out a lot of different stuff.