SFML community forums

General => Feature requests => Topic started by: sph3re on February 15, 2009, 01:46:15 pm

Title: Reset function for sf:Sprite
Post by: sph3re 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 :)
Title: Reset function for sf:Sprite
Post by: Laurent on February 15, 2009, 02:01:54 pm
Why do you need a Reset() function is you change scale, center and rotation anyway?
Title: Reset function for sf:Sprite
Post by: Nexus 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);
}
Title: Reset function for sf:Sprite
Post by: SamuraiCrow 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.
Title: Reset function for sf:Sprite
Post by: quasius 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.
Title: Reset function for sf:Sprite
Post by: Laurent 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
Title: Reset function for sf:Sprite
Post by: quasius 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:
Title: Reset function for sf:Sprite
Post by: Nexus 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.
Title: Reset function for sf:Sprite
Post by: Laurent 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:
Title: Reset function for sf:Sprite
Post by: christoph 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
Title: Reset function for sf:Sprite
Post by: sph3re 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.
Title: Reset function for sf:Sprite
Post by: Daazku 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
Title: Reset function for sf:Sprite
Post by: Nexus 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. ;)
Title: Reset function for sf:Sprite
Post by: Tank 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. ;)
Title: Reset function for sf:Sprite
Post by: Laurent 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?
Title: Reset function for sf:Sprite
Post by: Laurent on February 17, 2009, 05:23:57 pm
Ok sorry... my last post was a little bit rude ;)

Let's do it simpler. To me, the reason why this feature is requested doesn't make sense:
Quote
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're going to set new values according to the new image, not reset everything, right? So, what do you want this function for?

Apparently everyone agrees with this request, so maybe someone can give me a better reason, or a better way to convince me with this one :)
Title: Reset function for sf:Sprite
Post by: Daazku on February 17, 2009, 09:01:35 pm
I don't think this function is useful... you really want to reuse the sprite? Do

mySprite = Sprite();
Title: Reset function for sf:Sprite
Post by: csiz on February 17, 2009, 09:36:28 pm
Hmm me thinks the most important thing in Resize() is that after it the subrect of the Sprite to be set from the Image, like setting an image to a sprite for the first time.

But than it would be more useful just to change SetImage(Image) so that the subrect is reset.
Title: Reset function for sf:Sprite
Post by: Laurent on February 17, 2009, 11:04:00 pm
Quote
But than it would be more useful just to change SetImage(Image) so that the subrect is reset.

It has already been discussed, and actually it's not a good option :P