SFML community forums

Help => Graphics => Topic started by: Lafer on April 14, 2011, 05:36:38 pm

Title: [Sprite Movement] Question
Post 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:
Code: [Select]
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"?
Title: [Sprite Movement] Question
Post by: Fred_FS on April 14, 2011, 05:58:22 pm
Is it not supposed to look like this?
Code: [Select]

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?
Title: [Sprite Movement] Question
Post by: Lafer on April 14, 2011, 07:27:24 pm
Thank you very much!
It works now correctly.