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

Author Topic: Sprite::SetCenter odd behaviour  (Read 2198 times)

0 Members and 1 Guest are viewing this topic.

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Sprite::SetCenter odd behaviour
« on: June 05, 2009, 09:47:21 pm »
I almost always do a

Code: [Select]
sprite.SetImage(image);
sprite.SetPosition(400, 300);
sprite.SetCenter(sprite.GetSize()/2.f);


To have the sprite centered.

But if the sprite has some scale, i.e.:
Code: [Select]
sprite.SetImage(image);
sprite.SetPosition(400, 300);
sprite.SetScale(0.8f, 0.8f);
sprite.SetCenter(sprite.GetSize()/2.f);


It doesn't get centered correctly. GetSize() returns the corrected size given the sprite's scale, but I think that's something wrong with the centering on sprite drawing (maybe other shapes too)... as I would expect what I wrote to work.

In the docs it says: Set the center of the object, in coordinates relative to the top-left of the object (take 2 values).
So I get that those are not Image coordinates, but object's (drawable) ones.
But doing:

Code: [Select]
sprite.SetCenter(image.GetWidth()/2.f, image.GetHeight()/2.f);

works as you would think the previous code would.

Is this the expected behaviour? If it is, it would be nice to document that the center is taken as image-coords instead of object coords.

Thanks
-Martín

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Sprite::SetCenter odd behaviour
« Reply #1 on: June 05, 2009, 09:58:59 pm »
Quote
Is this the expected behaviour?

Yes it is. The center is given in local coordinates (what you call image coordinates), so this is incompatible with GetSize() which already takes the scale in account.

Quote
If it is, it would be nice to document that the center is taken as image-coords instead of object coords

The comments are already fixed in the sfml2 branch (I've added the "local" word ;))

But anyway, in SFML 2.0 there will be more powerful / consistent functions for geometry manipulation in drawable classes.
Laurent Gomila - SFML developer

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Sprite::SetCenter odd behaviour
« Reply #2 on: June 05, 2009, 10:29:53 pm »
Okey, thanks!

Glad to hear that from SFML2.

 

anything