显示圆和矩形
#include
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(10.f);
shape.setFillColor(sf::Color::Green);
shape.setPosition(0, 0);
sf::RectangleShape rect(sf::Vector2f(5, 10));
rect.setPosition(sf::Vector2f(20, 20));
rect.setFillColor(sf::Color(255, 255, 255, 128));
rect.setRotation(45);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
for (int i = 0; i < 50; i++) {
rect.setPosition(sf::Vector2f(20 + i * 5, 20 + i * 5));
rect.setFillColor(sf::Color(255-i*5, 255 - i * 5, 255, 128));
rect.setRotation(45 - i * 2);
window.draw(rect);
}
window.draw(shape);
window.display();
}
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
打印实时坐标
#include
#include
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Window");
sf::Vector2i mousePosition;
sf::Font font;
sf::Text text;
text.setFont(font);
text.setCharacterSize(90);
text.setFillColor(sf::Color::Black);
text.setPosition(20, 20);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
mousePosition = sf::Mouse::getPosition(window);
std::cout << "Mouse Position: (" << mousePosition.x << ", " << mousePosition.y << ")" << std::endl;
text.setString("Mouse Position: (" + std::to_string(mousePosition.x) + ", " + std::to_string(mousePosition.y) + ")");
window.clear(sf::Color::Yellow);
window.draw(text);
window.display();
}
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38