Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [Sprite Movement] Question  (Read 2325 times)

0 Members and 1 Guest are viewing this topic.

Lafer

  • Newbie
  • *
  • Posts: 2
    • View Profile
[Sprite Movement] Question
« 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"?

Fred_FS

  • Newbie
  • *
  • Posts: 48
    • View Profile
[Sprite Movement] Question
« Reply #1 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?

Lafer

  • Newbie
  • *
  • Posts: 2
    • View Profile
[Sprite Movement] Question
« Reply #2 on: April 14, 2011, 07:27:24 pm »
Thank you very much!
It works now correctly.

 

anything