1
Graphics / Animated sprite in SFML
« on: February 05, 2012, 10:34:37 am »Quote from: "Elgan"
Hope this helps, though I am terrible at explaining.
No, that's okay. I see what you mean. It will be good to design a good way of packaging animations, but I think I'll get the animation itself working first...
Quote from: "Nexus"
non-intrusive approach that just modifies one or multiple existing sprites
That's an interesting approach, and certainly one of the neater ones I should think. I'll take a look at Thor when I have a minute - looks like a pretty cool library in general! However, for my own animation class, I want to make it -- in the name of object oriented-ness -- a single self contained class if possible.
However, it's tricky. As you say, inheriting sf::Sprite will give you a load of unwanted member functions. The best approach would be to inherit from sf::Sprite and override those member functions, but they're not virtual in sf::Sprite, so it's not an option.
Option 2 would be inheriting from sf::Drawable. Then, if the animation has a sprite, all the position, colour, etc applied to the animation have to be duplicated to the sprite for drawing, which seems somewhat wasteful.
Finally, you could inherit from sf::Drawable and not have a sprite, but then you'd just end up re-implementing most of the sprite functionality in the animation...
Hmm... it's a difficult choice, I can see why you went for the `non-intrusive' option
What if I inherited sf::Sprite privately and just duplicated all the desired repeated functions with public inline 'proxy' functions which just called the corresponding private ones? If they were inline, there probably wouldn't even be performance loss that way. Mind you, RenderTarget is a friend of Drawable, so I guess this might break something...
Quote from: "HKei"
You think it makes sense to say "An animation is a sprite"?
I think it makes sense to say ``an animated sprite is a sprite'' And that's exactly what I'm making, an animated sprite. That said, I don't think inheritance will work in practice.