SFML更新函数没有移动精灵

时间:2015-12-02 02:01:17

标签: c++ opengl sfml

当前更新函数应该在每次调用时将精灵移动到左边10个像素,但精灵(cup1Sprite)是静态的而不是移动。我尝试使用sprite.rotate();并且精灵每帧都旋转(这是预期的),所以我编写更新函数以更新精灵位置的方式出了问题。任何人都可以建议出现问题吗?

代码: DrawCups.h

class DrawCups
{
public:
    DrawCups(sf::RenderWindow& window);
    ~DrawCups();

    void update();

    void drawCup1();

private:
    sf::RenderWindow& _window;
    //Cup1
    sf::Texture _cup1;        // the texture which will contain our pixel data
    sf::Sprite _cup1Sprite;         // the sprite which will actually draw it
};

DrawCups.cpp中的更新功能

void DrawCups::update()
{
    sf::Vector2f pos = this->_cup1Sprite.getPosition();
    pos.x+=10; 
    this->_cup1Sprite.setPosition(pos);
}

的main.cpp

int main()
{
    sf::RenderWindow window(sf::VideoMode(1366, 768), "Sorting Algorithm Visualisation: SFML");
    window.setFramerateLimit(60);
    DrawCups drawToWindow(window);

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

        drawToWindow.update();

        window.clear(sf::Color::White);
        drawToWindow.drawBench();
        drawToWindow.drawCup1();
        window.display();
    }

    return 0;
}

0 个答案:

没有答案