I tried writing a code. The purpose of it is to display a number on the screen, and then every time a part of the screen is clicked the number is increased by 100. However, this doesn't seem to work, so if you could help me out with this, I'd be grateful.
#include <SFML/Window.hpp>
#include <string>
#include <sstream>
#include <stdlib.h>
#include <SFML/Graphics.hpp>
void HandleMouseClick(sf::Mouse::Button click, int x, int y);
int game = 1000;
int main()
{
sf::RenderWindow window(sf::VideoMode(1024, 768), "My window");
sf::Text mytext;
std::stringstream ss; // #include <sstream>
ss << game;
mytext.setString( ss.str().c_str() );
window.draw(mytext);
window.display();
// 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::MouseButtonPressed)
HandleMouseClick(event.mouseButton.button, event.mouseMove.x, event.mouseMove.y);
// "close requested" event: we close the window
else if (event.type == sf::Event::Closed)
window.close();
}
}
return 0;
}
void HandleMouseClick(sf::Mouse::Button button, int x, int y)
{
if(x >= 0 && x < 1023 && y >= 145 && y < 380)
{
game = game + 100;
}
}