I'm trying to draw some text (an "X") at the position of the mouse after clicked. But the window only draw a dot. Does anybody know how to fix it. Thank you. Sorry if my english is bad
This is my code
#include <iostream>
#include <vector>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
int main()
{
// create the window
sf::RenderWindow window(sf::VideoMode(720, 720), "My window",sf::Style::Titlebar | sf::Style::Close);
window.setFramerateLimit(50);
std::vector<sf::Text*> shapes;
// run the program as long as the window is open
while (window.isOpen()){
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (window.pollEvent(event)){
if (event.type == sf::Event::MouseButtonReleased &&
event.mouseButton.button == sf::Mouse::Left) {
sf::Font font;
font.loadFromFile("font/arial.ttf");
sf::Text *shape = new sf::Text("X",font);
shape->setString("X");
shape->setCharacterSize(30);
shape->setPosition(event.mouseButton.x,event.mouseButton.y);
shape->setColor(sf::Color::Green);
shapes.push_back(shape);
}
// Clear screen
window.clear();
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
window.close();
}
// clear the window with black color
window.clear(sf::Color::Black);
// draw everything here...
// window.draw(...);
for(auto it=shapes.begin();it!=shapes.end();it++)
{
window.draw(**it);
}
// end the current frame
window.display();
}
return 0;
}