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

Author Topic: new sf::Sprite Method "void centerOrigin()"  (Read 6060 times)

0 Members and 1 Guest are viewing this topic.

Grundkurs

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
new sf::Sprite Method "void centerOrigin()"
« 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();

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: new sf::Sprite Method "void centerOrigin()"
« Reply #1 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?
Laurent Gomila - SFML developer

Grundkurs

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: new sf::Sprite Method "void centerOrigin()"
« Reply #2 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: new sf::Sprite Method "void centerOrigin()"
« Reply #3 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

StDH

  • Jr. Member
  • **
  • Posts: 56
  • {⛺.⛺}
    • View Profile
    • Worst ever ^^
Re: new sf::Sprite Method "void centerOrigin()"
« Reply #4 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)
<StDH> Imagine a girl writing you this: My farts smell good
<Slipxy> married.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: new sf::Sprite Method "void centerOrigin()"
« Reply #5 on: February 03, 2015, 07:54:16 am »
static_cast<unsigned>(float)
It's obviously not about how to do it... ::)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

SeriousITGuy

  • Full Member
  • ***
  • Posts: 123
  • Still learning...
    • View Profile
Re: new sf::Sprite Method "void centerOrigin()"
« Reply #6 on: February 11, 2015, 03:14:56 pm »
As I already stated in my previous request, 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 ;-) )

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: new sf::Sprite Method "void centerOrigin()"
« Reply #7 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.
Laurent Gomila - SFML developer

SeriousITGuy

  • Full Member
  • ***
  • Posts: 123
  • Still learning...
    • View Profile
Re: new sf::Sprite Method "void centerOrigin()"
« Reply #8 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.

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: new sf::Sprite Method "void centerOrigin()"
« Reply #9 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.