SFML community forums

General => Feature requests => Topic started by: Grundkurs on February 02, 2015, 01:41:05 pm

Title: new sf::Sprite Method "void centerOrigin()"
Post by: Grundkurs on February 02, 2015, 01:41:05 pm
Hey there,
i have a small feature request. Often i need to set the Origin of the Sprite to its center,
like
sprite.setOrigin(sprite.getLocalBounds().width / 2.f,
                (sprite.getLocalBounds().height / 2.f);

or as a function
void centerOrigin(sf::Sprite& sprite){
    sf::FloatRect bounds{sprite.getLocalBounds()};
    sprite.setOrigin(bounds.width /2.f, bounds.height /2.f);
}

it would be nice if the sf::Sprite class would provide a Method that sets the Origin to Center automatically, like:
sprite.centerOrigin();
Title: Re: new sf::Sprite Method "void centerOrigin()"
Post by: Laurent on February 02, 2015, 01:49:28 pm
As far as I remember, this addition has already been discussed, have you searched the forum first?
Title: Re: new sf::Sprite Method "void centerOrigin()"
Post by: Grundkurs on February 02, 2015, 02:00:20 pm
yes i searched the sub-forum "Feature Request" for Threads regarding the Topic "Origin", there are all together 19 Threads displayed, though only one of them kind of addressed my request
http://en.sfml-dev.org/forums/index.php?topic=15704.0
But he didnt get any answer and his request goes beyond my request. Sorry if i have overseen the Thread discussing the topic, but i didn't found it yet.
Title: Re: new sf::Sprite Method "void centerOrigin()"
Post by: eXpl0it3r on February 02, 2015, 02:02:15 pm
What about people who always need to put the origin on the bottom right, or top right, or bottom left, or 1/3 of size from the left side? ;)
What I'm trying to say is, that we usually don't add functions just to fit one specific use case.

Additionally if your sprite has uneven size, dividing by 2.f might create rasterization issues and as such people would again have to write their own free function or similar.
Title: Re: new sf::Sprite Method "void centerOrigin()"
Post by: StDH on February 03, 2015, 05:49:31 am
I'm for that feature =) it would be nice to see in SFML.

Additionally if your sprite has uneven size, dividing by 2.f might create rasterization issues and as such people would again have to write their own free function or similar.

static_cast<unsigned>(float)
Title: Re: new sf::Sprite Method "void centerOrigin()"
Post by: eXpl0it3r on February 03, 2015, 07:54:16 am
static_cast<unsigned>(float)
It's obviously not about how to do it... ::)
Title: Re: new sf::Sprite Method "void centerOrigin()"
Post by: SeriousITGuy on February 11, 2015, 03:14:56 pm
As I already stated in my previous request (http://en.sfml-dev.org/forums/index.php?topic=15704.0), setting specific relative origins (top-left, top-center, top-right etc.) would come in handy, not only centering the origin. Implementing offsets for the relative alignment would also be a nice addition. For me the rasterization "issue" with uneven sprites is not present, I have never worked with uneven sprites, I always work with sprite sizes in powers of 2 cause it makes life easier. But this "problem" could easily be adressed by such a function.

I still fully support this feature request. (And this time a response would be nice ;-) )
Title: Re: new sf::Sprite Method "void centerOrigin()"
Post by: Laurent on February 11, 2015, 03:46:20 pm
The problem is that sf::Transformable doesn't know the size of the entity, and even if it did, it wouldn't know when this size changes.

As for doing it in derived entities classes directly, that would be a lot of code duplication, and be confusing (setOrigin(Vector2f) is in Transformable, setOrigin(Corner) is in derived classes).

I don't see any clean design for such a function.
Title: Re: new sf::Sprite Method "void centerOrigin()"
Post by: SeriousITGuy on February 12, 2015, 09:44:14 am
Hmm, ok if such a function could not be generalized, then I think it won't be a valuable addition versus user defined functions.
I'm  tottaly ok with that, this clears this question up for me.
Thanks.
Title: Re: new sf::Sprite Method "void centerOrigin()"
Post by: Grimshaw on February 12, 2015, 02:19:52 pm
I see a clean design for that function:

void centerOrigin(object) as a global function, in the user's own code, its what I recommend :D

--

At most I would consider adding to Transform an anchor system or something similar, where you'd call instead Anchor(TopLeft | BottomRight | Center | Whatever). This way it would cover most common needs and still have a nearly clean API.