SFML community forums
Help => Graphics => Topic started by: Lafer on April 14, 2011, 05:36:38 pm
-
Good evening,
I am a beginner with SFML, and need help with some basic things.
My intention is to keep the sprite inside the window. I tried a lot and this is my result:
float maxheight = App.GetHeight() + Sprite.GetSize().x;
if(Sprite.GetPosition().x > maxheight)
Sprite.SetPosition(App.GetWidth() - Sprite.GetSize().x, Sprite.GetPosition().y);
It works pretty well, but there is one thing I don't agree with. If the Sprite is going to move right outside, it's pushed back a little. How can I remove that "push back"?
-
Is it not supposed to look like this?
float maxwidth = App.GetWidth() - Sprite.GetSize().x;
if( Sprite.GetPosition().x >= maxwidth )
Sprite.SetPosition( maxwidth, Sprite.GetPosition().y );
Or did I misunderstand what you wanted to do?
-
Thank you very much!
It works now correctly.