3
« on: February 12, 2016, 12:36:36 pm »
[Hi. I started learning SFML in the last week. If you think my question could be answered by reading the tutorials, please give me a link. Also if I'm doing something in an unecesserily complicated way, I'll appreciate it if you tell me. Thank you!]
I was trying display an image on the screen, and then put dots where the user pressed. Here's my code:
//This is a type I defined. For this question, it's enough to know that it has a Texture member.
static void create(imageAndButtons& myImage)
{
sf::Texture image(myImage.texture);
sf::Sprite mySprite(image);
sf::RenderWindow myWindow;
//Make window size match image size.
myWindow.create(sf::VideoMode(image.getSize().x,image.getSize().y),"screen");
myWindow.draw(mySprite);
myWindow.display();
sf::VertexArray point(sf::Points, 1);
sf::Event event;
while (true)
{
while (myWindow.pollEvent(event))
if (event.type == sf::Event::MouseButtonPressed)
{
point[0].position.x = event.mouseButton.x;
point[0].position.y = event.mouseButton.y;
myWindow.draw(point);
myWindow.display();
}
}
The very strange (to me) result of this code was that each time the user presses the mouse button the image disappears and reappears alternately, while the dots are added to the screen and remain all the time.
I'll be happy to know what I should change in my code. Also I'd very much like to understand why the image disappears, and what makes it to reappear (We never left the while loop!)