So I am trying to make a sprite to stay on screen, when my mouse is off-screen, and when the button is pressed.
The code:
Texture Temp;
Temp.loadFromFile("./Tiles/Boat.png");
Sprite Boat(Temp);
Boat.setScale(1.0, 1.0);
Event Action;
Keyboard Tastatura;
while (Game.isOpen())
{
while (Game.pollEvent(Action))
{
if (Action.type == Action.Closed)
{
Game.close();
}
if (Action.key.code==Tastatura.Space )
{
Boat.setPosition(static_cast<sf::Vector2f>(MousePoz.getPosition(Game)));
}
}
Game.clear(Color(139,0,139,255));
Game.draw(Boat);
Game.display();
}
Basically, when I press space, the sprite moves to my mouse position relative to the Game Window.
the problem is that when my moves out of the game window and space is pressed, the sprite moves off-screen too...
The boat is a small picture, and it loads correctly.
What can I do?
PS: Sorry if I made spelling mistakes.