Witam mam taki oto kod na chodzenie postaci. Kiedy go uruchamiam to wszystko wydaje się być ok ale jak tak sobie pochodzę chwilę tą postacią to w pewnym momencie ona zwalnia (nie na chwilę na stałe). Co może być źle? Czy potrzebny jest kod całej gry?
double frame = 0.44 /( double )( 2 );
short actualframe = 0;
sf::Clock animationclock;
if( sf::Keyboard::isKeyPressed( sf::Keyboard::Right ) )
{
Moving = 1;
direction = 2;
if( animationclock.getElapsedTime().asSeconds() >= frame )
{
animationclock.restart();
if( actualframe == 0 )
{
actualframe = 1;
RuthieGriffiths.setTextureRect( sf::IntRect( 3910, 2370, 940, 2500 ) );
}
else if( actualframe == 1 )
{
actualframe = 2;
RuthieGriffiths.setTextureRect( sf::IntRect( 4910, 2370, 900, 2500 ) );
}
else if( actualframe == 2 )
{
actualframe = 3;
RuthieGriffiths.setTextureRect( sf::IntRect( 2990, 2370, 940, 2500 ) );
}
else if( actualframe == 3 )
{
actualframe = 0;
RuthieGriffiths.setTextureRect( sf::IntRect( 4910, 2370, 900, 2500 ) );
}
}
}
if( sf::Keyboard::isKeyPressed( sf::Keyboard::Left ) )
{
Moving = 1;
direction = 3;
if( animationclock.getElapsedTime().asSeconds() >= frame )
{
animationclock.restart();
if( actualframe == 0 )
{
actualframe = 1;
RuthieGriffiths.setTextureRect( sf::IntRect( 3700, 0, 900, 2350 ) );
}
else if( actualframe == 1 )
{
actualframe = 2;
RuthieGriffiths.setTextureRect( sf::IntRect( 2800, 0, 900, 2350 ) );
}
else if( actualframe == 2 )
{
actualframe = 3;
RuthieGriffiths.setTextureRect( sf::IntRect( 4700, 0, 900, 2350 ) );
}
else if( actualframe == 3 )
{
actualframe = 0;
RuthieGriffiths.setTextureRect( sf::IntRect( 2800, 0, 900, 2350 ) );
}
}
}
if( sf::Keyboard::isKeyPressed( sf::Keyboard::Down ) )
{
Moving = 1;
direction = 0;
if( animationclock.getElapsedTime().asSeconds() >= frame )
{
animationclock.restart();
if( actualframe == 0 )
{
actualframe = 1;
RuthieGriffiths.setTextureRect( sf::IntRect( 943, 0, 800, 2300 ) );
}
else if( actualframe == 1 )
{
actualframe = 2;
RuthieGriffiths.setTextureRect( sf::IntRect( 0, 0, 800, 2300 ) );
}
else if( actualframe == 2 )
{
actualframe = 3;
RuthieGriffiths.setTextureRect( sf::IntRect( 1892, 0, 800, 2300 ) );
}
else if( actualframe == 3 )
{
actualframe = 0;
RuthieGriffiths.setTextureRect( sf::IntRect( 0, 0, 800, 2300 ) );
}
}
}
if( sf::Keyboard::isKeyPressed( sf::Keyboard::Up ) )
{
Moving = 1;
direction = 1;
if( animationclock.getElapsedTime().asSeconds() >= frame )
{
animationclock.restart();
if( actualframe == 0 )
{
actualframe = 1;
RuthieGriffiths.setTextureRect( sf::IntRect( 1830, 2300, 850, 2500 ) );
}
else if( actualframe == 1 )
{
actualframe = 2;
RuthieGriffiths.setTextureRect( sf::IntRect( 0, 2300, 850, 2500 ) );
}
else if( actualframe == 2 )
{
actualframe = 3;
RuthieGriffiths.setTextureRect( sf::IntRect( 895, 2300, 850, 2500 ) );
}
else if( actualframe == 3 )
{
actualframe = 0;
RuthieGriffiths.setTextureRect( sf::IntRect( 0, 2300, 850, 2500 ) );
}
}
}
if( sf::Keyboard::isKeyPressed( sf::Keyboard::Down ) && sf::Keyboard::isKeyPressed( sf::Keyboard::Right ) )
{
Moving = 1;
direction = 4;
if( animationclock.getElapsedTime().asSeconds() >= frame )
{
animationclock.restart();
if( actualframe == 0 )
{
actualframe = 1;
RuthieGriffiths.setTextureRect( sf::IntRect( 943, 0, 800, 2300 ) );
}
else if( actualframe == 1 )
{
actualframe = 2;
RuthieGriffiths.setTextureRect( sf::IntRect( 0, 0, 800, 2300 ) );
}
else if( actualframe == 2 )
{
actualframe = 3;
RuthieGriffiths.setTextureRect( sf::IntRect( 1892, 0, 800, 2300 ) );
}
else if( actualframe == 3 )
{
actualframe = 0;
RuthieGriffiths.setTextureRect( sf::IntRect( 0, 0, 800, 2300 ) );
}
}
}
if( sf::Keyboard::isKeyPressed( sf::Keyboard::Down ) && sf::Keyboard::isKeyPressed( sf::Keyboard::Left ) )
{
Moving = 1;
direction = 5;
if( animationclock.getElapsedTime().asSeconds() >= frame )
{
animationclock.restart();
if( actualframe == 0 )
{
actualframe = 1;
RuthieGriffiths.setTextureRect( sf::IntRect( 943, 0, 800, 2300 ) );
}
else if( actualframe == 1 )
{
actualframe = 2;
RuthieGriffiths.setTextureRect( sf::IntRect( 0, 0, 800, 2300 ) );
}
else if( actualframe == 2 )
{
actualframe = 3;
RuthieGriffiths.setTextureRect( sf::IntRect( 1892, 0, 800, 2300 ) );
}
else if( actualframe == 3 )
{
actualframe = 0;
RuthieGriffiths.setTextureRect( sf::IntRect( 0, 0, 800, 2300 ) );
}
}
}
if( sf::Keyboard::isKeyPressed( sf::Keyboard::Up ) && sf::Keyboard::isKeyPressed( sf::Keyboard::Right ) )
{
Moving = 1;
direction = 6;
if( animationclock.getElapsedTime().asSeconds() >= frame )
{
animationclock.restart();
if( actualframe == 0 )
{
actualframe = 1;
RuthieGriffiths.setTextureRect( sf::IntRect( 1830, 2300, 850, 2500 ) );
}
else if( actualframe == 1 )
{
actualframe = 2;
RuthieGriffiths.setTextureRect( sf::IntRect( 0, 2300, 850, 2500 ) );
}
else if( actualframe == 2 )
{
actualframe = 3;
RuthieGriffiths.setTextureRect( sf::IntRect( 895, 2300, 850, 2500 ) );
}
else if( actualframe == 3 )
{
actualframe = 0;
RuthieGriffiths.setTextureRect( sf::IntRect( 0, 2300, 850, 2500 ) );
}
}
}
if( sf::Keyboard::isKeyPressed( sf::Keyboard::Up ) && sf::Keyboard::isKeyPressed( sf::Keyboard::Left ) )
{
Moving = 1;
direction = 7;
if( animationclock.getElapsedTime().asSeconds() >= frame )
{
animationclock.restart();
if( actualframe == 0 )
{
actualframe = 1;
RuthieGriffiths.setTextureRect( sf::IntRect( 1830, 2300, 850, 2500 ) );
}
else if( actualframe == 1 )
{
actualframe = 2;
RuthieGriffiths.setTextureRect( sf::IntRect( 0, 2300, 850, 2500 ) );
}
else if( actualframe == 2 )
{
actualframe = 3;
RuthieGriffiths.setTextureRect( sf::IntRect( 895, 2300, 850, 2500 ) );
}
else if( actualframe == 3 )
{
actualframe = 0;
RuthieGriffiths.setTextureRect( sf::IntRect( 0, 2300, 850, 2500 ) );
}
}
}
switch( Moving )
{
case 1:
switch( direction )
{
case 0:
RuthieGriffiths.move( 0, 0.15 );
break;
case 1:
RuthieGriffiths.move( 0, - 0.15 );
break;
case 2:
RuthieGriffiths.move( 0.15, 0 );
break;
case 3:
RuthieGriffiths.move( - 0.15, 0 );
break;
case 4:
RuthieGriffiths.move( 0.15, 0.15 );
break;
case 5:
RuthieGriffiths.move( - 0.15, 0.15 );
break;
case 6:
RuthieGriffiths.move( 0.15, - 0.15 );
break;
case 7:
RuthieGriffiths.move( - 0.15, - 0.15 );
break;
}
break;
case 0:
switch( direction )
{
case 0:
RuthieGriffiths.setTextureRect( sf::IntRect( 0, 0, 800, 2300 ) );
break;
case 1:
RuthieGriffiths.setTextureRect( sf::IntRect( 0, 2300, 800, 2500 ) );
break;
case 2:
RuthieGriffiths.setTextureRect( sf::IntRect( 4910, 2370, 900, 2500 ) );
break;
case 3:
RuthieGriffiths.setTextureRect( sf::IntRect( 2800, 0, 900, 2350 ) );
break;
case 4:
RuthieGriffiths.setTextureRect( sf::IntRect( 0, 0, 800, 2300 ) );
break;
case 5:
RuthieGriffiths.setTextureRect( sf::IntRect( 0, 0, 800, 2300 ) );
break;
case 6:
RuthieGriffiths.setTextureRect( sf::IntRect( 0, 2300, 800, 2500 ) );
break;
case 7:
RuthieGriffiths.setTextureRect( sf::IntRect( 0, 2300, 800, 2500 ) );
break;
}
break;
}
gra.draw( RuthieGriffiths );
Moving = 0;