SFML community forums

Help => General => Topic started by: paupav on July 27, 2014, 04:25:59 pm

Title: Bug report
Post by: paupav on July 27, 2014, 04:25:59 pm
For some reason in this code:
#include <iostream>
#include <SFML/Graphics.hpp>
#include <ctime>


int main()
{
    enum Direction{Down, Left, Right, Up};
    sf::Vector2i cut(1, Down);
    sf::Vector2i screenRes(800,600);
    sf::Vector2f pos(0, 0);
    sf::RenderWindow window(sf::VideoMode(screenRes.x,screenRes.y), "My ghaaaame");
    sf::Time eTime;
    sf::Texture pTexture;
    sf::Sprite pImage;
    sf::Clock clock1;
    float charSpeed = 2.5;
    int refresh = 75;

    if(!pTexture.loadFromFile("playerimage.png"))
            std::cout << eTime.asMicroseconds() << " -No player image in the folder!" << std::endl;


    while(window.isOpen())
    {
        pImage.setTexture(pTexture);

        eTime = clock1.getElapsedTime();


        sf::Event event;
        while(window.pollEvent(event))
        {
        switch(event.type)
        {
            case sf::Event::Closed:
                window.close();
            break;
        }
        }
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
        {
            cut.y = Right;
            if(eTime.asMilliseconds()>= refresh)
            {
            cut.x++;
            clock1.restart();
            }
            pos.x+= charSpeed;
        }
        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
        {
            cut.y = Left;
            if(eTime.asMilliseconds()>= refresh)
            {
            cut.x++;
            clock1.restart();
            }
            pos.x-= charSpeed;
        }
        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
        {
            cut.y = Down;
            if(eTime.asMilliseconds()>= refresh)
            {
            cut.x++;
            clock1.restart();
            }
            pos.y+= charSpeed;
        }
        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
        {
            cut.y = Up;
            if(eTime.asMilliseconds()>= refresh)
            {
            cut.x++;
            clock1.restart();
            }

            pos.y-= charSpeed;
        }

    if(cut.x >= 3)
        cut.x = 0;
    pImage.setTextureRect(sf::IntRect(cut.x * 32, cut.y * 32, 32, 32));
    pImage.setPosition(pos.x, pos.y);
    window.clear(sf::Color::White);
    window.draw(pImage);
    window.display();
    //window.setFramerateLimit(15);
    }

}

when charSpeed = 2.5
sprite becomes deformed (attachment)

with any other number it is fine. Even with 2.4 and 2.51

http://www.youtube.com/watch?v=cV8_jVR3qQw
Title: Re: Bug report
Post by: Nexus on July 27, 2014, 04:43:35 pm
Have you searched before posting? This is not a bug, this is documented behavior concerning the rasterizer.

http://en.sfml-dev.org/forums/index.php?topic=15747.msg112372#msg112372
...and if you follow my links there, you'll find many more.

And please post in the Help section, this forum is for general design discussions.
(Yes, Laurent should finally replace the "for everything that is not a help request" description :P)