I have a base class called SpriteSheet which has two children, RotatedSpriteSheet and FlippedSpriteSheet. SpriteSheet contains frames, RotatedSpriteSheet includes those frames + frames for rotations and FlippedSpriteSheet contains the original frames + flipped frames.
I have another class called Sprite which references a SpriteSheet. The Sprite stores its position, current animation frame, angle, whether the image is flipped or not, etc. When the Sprite updates it’s animation, it makes a call like:
imageData = _spriteSheet.calculateFrame(animationFrame, flipped, angle);
As you can see, this is pretty silly design because SpriteSheet shouldn’t have a function that asks for flipped or angle when the base SpriteSheet class doesn’t use that data.
I think the problem stems from the fact that I don’t want to have multiple “Sprite” objects, like RotatedSprite, AlphadSprite, FlippedSprite, FlippedAndRotatedSprite… it seems too cumbersome.
The only solution I can think of is that instead of calculateFrame() taking the animation frame, flipped state and the angle, I could pass it a reference to the Sprite object and let the SpriteSheet (and it’s children) “inspect” the sprite and calculate the data itself. The problem with that design is that I’d have to make extra data public that’s only local to the sprite (animation data mainly). I don’t think that’s such a big deal. Is this the best solution?
Thanks for your tips and suggestions.
Create a separate
Transformationhierarchy that encapsulates all the required information for transforming a sprite or sprite sheet.