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

Author Topic: Reset function for sf:Sprite  (Read 12079 times)

0 Members and 2 Guests are viewing this topic.

sph3re

  • Newbie
  • *
  • Posts: 3
    • View Profile
Reset function for sf:Sprite
« on: February 15, 2009, 01:46:15 pm »
I've got an idea for a additional sf::Sprite function, Reset(). It resets scaling, rotation, center, etc to std value.
This could be useful when a Sprite has got several Images with different sizes. Every time you switch between them, you have to rescale the sprite, set a new center, etc
You don't need more than 5 minutes to write that function yourself, but humans are sick so I would be very pleased if that function exists :)
excuse my English, I'm German ;)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Reset function for sf:Sprite
« Reply #1 on: February 15, 2009, 02:01:54 pm »
Why do you need a Reset() function is you change scale, center and rotation anyway?
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Reset function for sf:Sprite
« Reply #2 on: February 15, 2009, 03:39:16 pm »
Besides that, you can easily add functionality to sprites by writing free functions. I did that, too, for example:

Code: [Select]
void AlignCenter(sf::Sprite& Sprite)
{
Sprite.SetCenter(Sprite.GetSize() / 2.f);
}
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

SamuraiCrow

  • Newbie
  • *
  • Posts: 40
    • Yahoo Instant Messenger - samuraileumas
    • View Profile
Reset function for sf:Sprite
« Reply #3 on: February 16, 2009, 02:20:40 am »
In raw OpenGL it could be accomplished by a GL_LoadIdentity() (I hope I spelled that according to the API spelling) so I would hope it should be easy to do with SFML.

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Reset function for sf:Sprite
« Reply #4 on: February 16, 2009, 05:57:36 am »
Quote from: "Nexus"
Besides that, you can easily add functionality to sprites by writing free functions. I did that, too, for example:

Code: [Select]
void AlignCenter(sf::Sprite& Sprite)
{
Sprite.SetCenter(Sprite.GetSize() / 2.f);
}


Eww...  yuck.  Just edit the SFML source if you want to add that.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Reset function for sf:Sprite
« Reply #5 on: February 16, 2009, 07:57:11 am »
Quote
In raw OpenGL it could be accomplished by a GL_LoadIdentity() (I hope I spelled that according to the API spelling) so I would hope it should be easy to do with SFML.

Do you really think I'm storing my sprites' transformations into the OpenGL model-view matrix? ;)
It would rather look like this:
Code: [Select]
void Sprite::Reset()
{
    myPosition = Vector2f(0, 0);
    myRotation = 0;
    myScale = Vector2f(0, 0);
    myCenter = Vector2f(0, 0);
}


But like I said, this function doesn't make any sense to me.

Quote
Eww... yuck. Just edit the SFML source if you want to add that.

Do that if you want to:
- get more work when upgrading to a new version of SFML, just to put back all your modifications
- make sure people won't be able to compile or run your program unless they get your version of SFML
Laurent Gomila - SFML developer

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Reset function for sf:Sprite
« Reply #6 on: February 16, 2009, 05:48:24 pm »
Quote from: "Laurent"
Do that if you want to:
- get more work when upgrading to a new version of SFML, just to put back all your modifications
- make sure people won't be able to compile or run your program unless they get your version of SFML


Good points.  But merging something like that is not that difficult.  As for people not being able to compile/run it, I guess that's true; but who really distributes software with instructions to go obtain some libraries before it will run?

Edit:  Setting the scale to (0,0) in your sample reset function seems like a bad idea...   :wink:

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Reset function for sf:Sprite
« Reply #7 on: February 16, 2009, 06:01:42 pm »
Quote from: "quasius"
Eww...  yuck.  Just edit the SFML source if you want to add that.
Which advantage do you expect from modifying the source instead of creating an independent global function? Or do you just mean "free functions are not appropriate in an object-oriented language"? I don't hope so...

Do you know the adapter pattern? The idea behind it points into the same direction. If you need a specific interface, you do not change the original class, but wrap it in order to achieve the requested functionality.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Reset function for sf:Sprite
« Reply #8 on: February 16, 2009, 06:59:15 pm »
Quote
Edit: Setting the scale to (0,0) in your sample reset function seems like a bad idea

Oops :oops:
Laurent Gomila - SFML developer

christoph

  • Full Member
  • ***
  • Posts: 102
    • View Profile
    • http://www.christoph-egger.org
Reset function for sf:Sprite
« Reply #9 on: February 16, 2009, 07:59:53 pm »
Quote from: "quasius"

Good points.  But merging something like that is not that difficult.  As for people not being able to compile/run it, I guess that's true; but who really distributes software with instructions to go obtain some libraries before it will run?

That's why rpm apt pacman and such do the library downloading automagically for the user

sph3re

  • Newbie
  • *
  • Posts: 3
    • View Profile
Reset function for sf:Sprite
« Reply #10 on: February 16, 2009, 09:00:17 pm »
It was just an idea, you dont have to kill me. I haven't seen the disadvantages of that, sorry. I never developed anything like a library so please give your opinion in a way, noone has to feel attacked. Even not someone who did his first post in this forum! Belive me, I only wanted to be helpful.
excuse my English, I'm German ;)

Daazku

  • Hero Member
  • *****
  • Posts: 896
    • View Profile
Reset function for sf:Sprite
« Reply #11 on: February 16, 2009, 11:07:21 pm »
Quote from: "sph3re"
It was just an idea, you dont have to kill me. I haven't seen the disadvantages of that, sorry. I never developed anything like a library so please give your opinion in a way, noone has to feel attacked. Even not someone who did his first post in this forum! Belive me, I only wanted to be helpful.


Calm down! No one attacked you :p
Pensez à mettre le tag [Résolu] une fois la réponse à votre question trouvée.
Remember to add the tag [Solved] when you got an answer to your question.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Reset function for sf:Sprite
« Reply #12 on: February 16, 2009, 11:56:49 pm »
sph3re, we just discussed about the pros and cons of a Reset() function. No one is blaming you. ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Reset function for sf:Sprite
« Reply #13 on: February 17, 2009, 02:33:27 am »
What I ask myself is: What's actually the point of not adding such a function? I mean, it's a minor thing, which can of course be implemented easily and fast by everyone. But that is the same with many other things, which can just be implemented by the proper developer himself. We would end up in a huge code redundancy and won't need a library at all, since everybody can implement stuff theirselves. ;)
Would a Reset() hurt in this specific case? I don't need the functionality, just wondering how much discussion it produces, instead of just adding it to the library. ;)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Reset function for sf:Sprite
« Reply #14 on: February 17, 2009, 08:06:27 am »
Quote
It was just an idea, you dont have to kill me. I haven't seen the disadvantages of that, sorry. I never developed anything like a library so please give your opinion in a way, noone has to feel attacked. Even not someone who did his first post in this forum! Belive me, I only wanted to be helpful.

Nobody's killing you ;)
I'm just trying to know if it makes sense. You know, adding a new function, even a simple one like this, is not straight-forward. I first need to know why it's requested, and decide if its makes sense, if it's consistent with the API, etc.

Quote
What I ask myself is: What's actually the point of not adding such a function?

Because it's useless? If I was thinking like that, SFML would already be bloated with tons of functions that would be more or less useful. You would certainly find the convenience function you're looking for, but it would be lost among hundreds of others that you don't care about.
I never add a function unless I'm sure it makes sense, it's consistent etc... (see above :D).

So, back to my main concern: why would this function be so useful, except for the reason that Mr X would have to use it a lot in it's particular program and doesn't want to write 5 lines of code himself?
Laurent Gomila - SFML developer