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

Author Topic: Sprite setScale problem  (Read 1428 times)

0 Members and 2 Guests are viewing this topic.

paul.mihaita

  • Newbie
  • *
  • Posts: 16
    • View Profile
Sprite setScale problem
« on: March 19, 2013, 02:16:14 pm »
Quote
sf::Event event;
    sf::Texture texture_patrat;
    sf::Texture texture_background;
    texture_patrat.loadFromFile("Patrat.png");
    texture_background.loadFromFile("Background.png");
    sf::Sprite patrat;
    sf::Sprite background;
    patrat.setTexture(texture_patrat);
    background.setTexture(texture_background);
    sf::VideoMode screen=sf::VideoMode::getDesktopMode();
    sf::RenderWindow window(sf::VideoMode(800,600), "SFML window",sf::Style::Fullscreen);
    window.setFramerateLimit(30);
    sf::Vector2f dimensiuni;
    float newsizea,newsizeb;
    newsizea=screen.width/1680;
    newsizeb=screen.height/1050;
    sf::Vector2f x,y;
    x=patrat.getScale();
    y=background.getScale();
    background.setScale(x.x*newsizea,x.y*newsizeb);
    patrat.setScale(y.x*newsizea,y.y*newsizeb);
    dimensiuni=patrat.getPosition();
    while(window.isOpen())
    {
        while(window.pollEvent(event))
        {
            if(event.type == sf::Event::KeyPressed)
            {
                if(event.key.code==sf::Keyboard::Escape)
                {
                    window.close();
                }
                if(event.key.code==sf::Keyboard::Up&&dimensiuni.y-20>=0)
                {
                    dimensiuni.y-=20;
                    patrat.setPosition(dimensiuni.x,dimensiuni.y);
                }
                if(event.key.code==sf::Keyboard::Up&&dimensiuni.y-20<0)
                {
                    dimensiuni.y=0;
                    patrat.setPosition(dimensiuni.x,dimensiuni.y);
                }
                if(event.key.code==sf::Keyboard::Down&&dimensiuni.y+20<=screen.height-200)
                {
                    dimensiuni.y+=20;
                    patrat.setPosition(dimensiuni.x,dimensiuni.y);
                }
                if(event.key.code==sf::Keyboard::Down&&dimensiuni.y+20>screen.height-200)
                {
                    dimensiuni.y=screen.height-200;
                    patrat.setPosition(dimensiuni.x,dimensiuni.y);
                }
                if(event.key.code==sf::Keyboard::Right&&dimensiuni.x+20<=screen.width-200)
                {
                    dimensiuni.x+=20;
                    patrat.setPosition(dimensiuni.x,dimensiuni.y);
                }
                if(event.key.code==sf::Keyboard::Right&&dimensiuni.x+20>screen.width-200)
                {
                    dimensiuni.x=screen.width-200;
                    patrat.setPosition(dimensiuni.x,dimensiuni.y);
                }
                if(event.key.code==sf::Keyboard::Left&&dimensiuni.x-20>=0)
                {
                    dimensiuni.x-=20;
                    patrat.setPosition(dimensiuni.x,dimensiuni.y);
                }
                if(event.key.code==sf::Keyboard::Left&&dimensiuni.x-20<0)
                {
                    dimensiuni.x=0;
                    patrat.setPosition(dimensiuni.x,dimensiuni.y);
                }
            }
        }
        window.draw(background);
        window.draw(patrat);
        window.display();
    }
    return 0;
}

My problem is that if i use sprite.setScale(0.5,0.5) it works but if i use sprite.setScale(newsezia,newsizeb) it doesn't work.I don't know why the setScale doesn't work if i use variables but with numbers it works.

paul.mihaita

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Sprite setScale problem
« Reply #1 on: March 19, 2013, 03:44:38 pm »
Problem solved

 

anything