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

Author Topic: After using setScale, sprite not showing on the RenderWindow  (Read 1161 times)

0 Members and 1 Guest are viewing this topic.

reethok

  • Newbie
  • *
  • Posts: 23
    • View Profile
    • Email
After using setScale, sprite not showing on the RenderWindow
« on: February 17, 2015, 02:31:23 pm »
I have tested without setScale and in that case it does show the sprite (tho only a part of it fits the window).

Here's the code:

void Game::showSplash()
{
        sf::Texture splash_txt;
        if (!splash_txt.loadFromFile("splash.jpg"))
        {
                std::cout << "Cant load splash" << std::endl;
        }

        sf::Sprite splash_spr;
        splash_spr.setTexture(splash_txt);
        splash_spr.setScale(xscale, yscale);

        mainWindow.draw(splash_spr);
        sf::Clock clock;

        while (clock.getElapsedTime().asSeconds() < 10)
        {
                mainWindow.display();
        }

        gameState = GameState::MAIN_MENU;
}
 

xscale and yscale are static variables from the class Game.  I also have tried with different combinations of display(), draw() and clear(), such as:

mainWindow.clear();
mainWindow.draw(splash_spr);
mainWindow.display();

What am I doing wrong? D:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: After using setScale, sprite not showing on the RenderWindow
« Reply #1 on: February 17, 2015, 02:32:34 pm »
What's the value of xscale and yscale?
Laurent Gomila - SFML developer

reethok

  • Newbie
  • *
  • Posts: 23
    • View Profile
    • Email
Re: After using setScale, sprite not showing on the RenderWindow
« Reply #2 on: February 17, 2015, 02:36:12 pm »
xscale = xresolution / 1920;
yscale = yresolution / 1080;

In this case,

xscale is 6.85714285714 and yscale is 0.66666666666.

I'm using SFML 2.2, by the way, and thanks for the super fast reply o.o

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: After using setScale, sprite not showing on the RenderWindow
« Reply #3 on: February 17, 2015, 03:08:50 pm »
Quote
xscale is 6.85714285714
That's a lot, probably too much.

Anyway, instead of trying to guess what happens, play with different values scales and see what happens to your entity (i.e. at why it eventually goes out of the screen).
Laurent Gomila - SFML developer

 

anything