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

Author Topic: Sprite draw problem. or bug?  (Read 2228 times)

0 Members and 1 Guest are viewing this topic.

underww

  • Newbie
  • *
  • Posts: 34
    • View Profile
Sprite draw problem. or bug?
« on: December 31, 2013, 12:29:43 pm »
I found sometimes SFML draw a sprite incorrectly on a particular position or in some cases.

For example, this code can't draw a sprite correctly.

I tested it on SFML 2.1 stable version and latest version also.

Here is the source code and the result screen.

        sf::RenderWindow window(sf::VideoMode(800, 600), "Test", sf::Style::Close);

        sf::Texture texture;
        texture.loadFromFile("texture.png");

        sf::Sprite sprite(texture);
        sprite.setPosition(16.49849838f, 16.49849838f);

        sf::Sprite sprite2(texture);
        sprite2.setPosition(16.5f, 50.f);

        sf::Sprite sprite3(texture);
        sprite3.setPosition(16.f, 85.f);

        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }

                window.clear();
                window.draw(sprite);
                window.draw(sprite2);
                window.draw(sprite3);
                window.display();
        }
 




Only third one draw normally.

Actually it can avoid using just integer position.

But, when I draw an animation like this ( move(velocity * dt.asSeconds(); )

SFML will draw an incorrect image a while.

Also sf::Font looks have the same problem.
« Last Edit: December 31, 2013, 12:40:09 pm by underww »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Sprite draw problem. or bug?
« Reply #1 on: December 31, 2013, 01:02:22 pm »
Yes, this is the expected behavior, and it's the only way to create smooth (sub-pixel) transitions. If you want pixel-perfect rendering, round the coordinates.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything