Have you ever wanted to have your own mouse cursor for you game or your application? Well… now you can!

First you need to deactivate mouse cursor in your SFML window:

window.setMouseCursorVisible(false);

And then you only need to show an sf::Sprite( or equivalent) positioned in the coordinates of the mouse:

sf::Sprite cursor;

// ...

while(window.isOpen())
{
     //...

     cursor.setPosition(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y);

     window.clear();
     window.draw(cursor);
     window.display();
}

And that’s all. Now you have your own custom mouse cursor.

Here is a complet example using sf::CircleShape as the mouse cursor. I setted the origin of the circle to the center because the click position of mouse would fall in the exterior of the circle.

#include <SFML/Graphics.hpp>

int main()
{
	sf::RenderWindow window(sf::VideoMode(800,600), "Custom mouse cursor");
	window.setMouseCursorVisible(false);

	// Create a CircleShape with radius 10
	sf::CircleShape cursor(10);
	// Set the origin of the cursor at the center of it
	cursor.setOrigin(cursor.getGlobalBounds().width/2, cursor.getGlobalBounds().height/2);

	while (window.isOpen())
	{
	    sf::Event event;
	    while (window.pollEvent(event))
	    {
		if (event.type == sf::Event::Closed)
		    window.close();
	    }

	    cursor.setPosition(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y);

	    window.clear();
	    window.draw(cursor);
	    window.display();
	}
}

For a more complex tutorial about custom mouse cursor visit eXpl0it3r’s tutorial.

You can find the source code on GitHub.