Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Invisible sprite when "move keys" continuously pressed  (Read 1282 times)

0 Members and 1 Guest are viewing this topic.

tandan_prashant

  • Newbie
  • *
  • Posts: 3
    • View Profile
Invisible sprite when "move keys" continuously pressed
« on: February 23, 2018, 02:24:59 pm »
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);
        }
    }