Hey Guys .. don't know what exactly happens but sprite(head) becomes invisible when I move it left and right by continuously pressing the left right keys but it is visible while moving up and down.
code ::
if( sf::Keyboard::isKeyPressed(sf::Keyboard::Left)){
if(head.getPosition().x > head.getSize().x/2){
position.x -= speed * deltaTime;
head.setRotation(0.f);
}
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)){
if(head.getPosition().x < window.getSize().x-head.getSize().x/2){
position.x += speed *deltaTime;
head.setRotation(0.f);
}
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)){
if(head.getPosition().y < window.getSize().y-head.getSize().y/2){
position.y += speed *deltaTime;
head.setRotation(90.f);
if(!faceRight)
head.setRotation(270.f);
}
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)){
if( head.getPosition().y > head.getSize().y/2){
position.y -= speed *deltaTime;
head.setRotation(270.f);
if(!faceRight)
head.setRotation(90.f);
}
}