Hello
I have a problem and i have been trying to solve it but i can't.
I have a game while loop and i have a varible called time which is set to 0. I want this variable to increment till 255 and when it reach that number i want it to decrement to 0, and keep incrementing and decrementing forever.
Did you assign up = false initially? It must be bool up = true; or that problem would occur.
EDIT: lines 1 and 2 should be outside the while loop and lines 3-10 inside.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
int Time = 0;
bool up = true;
while(Game.IsRunning())
{
if( up )
++Time;
else
--Time;
if( Time >= 255 ) up = false;// added inequalities as safeguard against passing over limit value.
elseif( Time <= 0 ) up = true;// more efficient
std::cout<<Time<<"\n";
}