Files
hwr2023_b/CPlusPlus/sfml/main.cpp
T
david 6064e56327 add sfml project
add wxWidgets project
2025-02-26 16:30:42 +01:00

47 lines
929 B
C++

#include "SFML/Graphics.hpp"
using namespace sf;
int main()
{
RenderWindow window(VideoMode({ 640, 480 }), "Hello World Example");
CircleShape circle(100.0f);
circle.setFillColor(Color(200, 0, 0));
Texture texture("assets/card_clubs_02.png");
Sprite sprite(texture);
while (window.isOpen())
{
while (const std::optional event = window.pollEvent())
{
if (event->is<Event::Closed>())
{
window.close();
}
//else if (event->is<Event::KeyPressed>())
else if (const Event::KeyPressed* keyPressed = event->getIf<Event::KeyPressed>())
{
if (keyPressed->scancode == Keyboard::Scancode::Escape) {
window.close();
}
}
}
// move circle
if (Keyboard::isKeyPressed(Keyboard::Scancode::Right))
{
circle.move(Vector2f(1, 0));
}
// clear window to start every from scratch
window.clear();
window.draw(circle);
window.draw(sprite);
window.display();
}
return 0;
}