Untitled
unknown
plain_text
2 years ago
670 B
4
Indexable
#include <SFML/Graphics.hpp>
int main() {
    sf::RenderWindow window(sf::VideoMode(800, 600), "Simple Animation");
    sf::CircleShape ball(50);
    ball.setFillColor(sf::Color::Red);
    float dx = 2.0f;
    float dy = -2.0f;
    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed)
                window.close();
        }
        ball.move(dx, dy);
        if (ball.getPosition().y > 550 || ball.getPosition().y < 0)
            dy = -dy;
        window.clear();
        window.draw(ball);
        window.display();
    }
    return 0;
}
Editor is loading...