SFML community forums
General => Feature requests => Topic started 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 :)
-
Why do you need a Reset() function is you change scale, center and rotation anyway?
-
Besides that, you can easily add functionality to sprites by writing free functions. I did that, too, for example:
void AlignCenter(sf::Sprite& Sprite)
{
Sprite.SetCenter(Sprite.GetSize() / 2.f);
}
-
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.
-
Besides that, you can easily add functionality to sprites by writing free functions. I did that, too, for example:
void AlignCenter(sf::Sprite& Sprite)
{
Sprite.SetCenter(Sprite.GetSize() / 2.f);
}
Eww... yuck. Just edit the SFML source if you want to add that.
-
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:
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.
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
-
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:
-
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.
-
Edit: Setting the scale to (0,0) in your sample reset function seems like a bad idea
Oops :oops:
-
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
-
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.
-
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
-
sph3re, we just discussed about the pros and cons of a Reset() function. No one is blaming you. ;)
-
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. ;)
-
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.
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?
-
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:
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 :)
-
I don't think this function is useful... you really want to reuse the sprite? Do
mySprite = Sprite();
-
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.
-
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