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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - kingwill

Pages: [1]
1
Graphics / changing texture on keypress
« on: July 08, 2013, 02:15:20 am »
hello i was experimenting trying to change the texture of a sprite on keypress but i realized that on keypress nothing happens what could i do to fix this problems



   sf::Texture tex[3];
   if(!tex[0].loadFromFile("data/Meifront.png",sf::IntRect(0,0,60.75f,76.0f))){}
   if(!tex[1].loadFromFile("data/Meifront.png",sf::IntRect(0,0,121.5f,76.0f))){}
   if(!tex[2].loadFromFile("data/Meifront.png",sf::IntRect(0,0,183.0f,76.0f))){}
   spr.setTexture(tex[0]);


void Game::GameLoop()
{

    while(window.isOpen())
    {
        while(window.pollEvent(e))
        {
            switch(e.type)
            {
                case sf::Event::Closed:
                    window.close();

                case sf::Event::KeyPressed :
                    if(e.key.code == sf::Keyboard::Escape)
                    {
                        window.close();
                    }
                    if(e.key.code == sf::Keyboard::Left)
                    {
                        tex[0].update(window, spr.getPosition().x, spr.getPosition().y);
                        spr.setTexture(tex[0]);
                        //Player1->move(-3,0);
                          }
                    if(e.key.code == sf::Keyboard::Right)
                    {
                        spr.setTexture(tex[1]);
                        Player1->move(3,0);
                    }
                    if(e.key.code == sf::Keyboard::Up)
                    {
                                                spr.setTexture(tex[2]);
                        }
                    if(e.key.code == sf::Keyboard::Down)
                    {
                        spr.setTexture(tex[3]);
                        }

                    }//switch
            }//while loop






 

Pages: [1]