SFML community forums

Help => Graphics => Topic started by: nitram_cero on June 05, 2009, 09:47:21 pm

Title: Sprite::SetCenter odd behaviour
Post by: nitram_cero 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
Title: Sprite::SetCenter odd behaviour
Post by: Laurent 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.
Title: Sprite::SetCenter odd behaviour
Post by: nitram_cero on June 05, 2009, 10:29:53 pm
Okey, thanks!

Glad to hear that from SFML2.