Multi page sprite sheet.

Hi folks. Question of the day:

I have a sprite class which currently runs on a single sprite sheet. It self advances and retreats as needed, works lovely.

But at present the Parent class holds the Texture, the child just holds pointers and returns an empty Rectangle for the draw routine to use.

I’m now at the point where some sprites are needing multiple sheets. I want to pass all the sheets to the class and store them in a list, but this poses a problem. This means the child class has to pass a texture back to the parent class for drawing.

Or is this a problem? Is creating the required texture in the child class going to be that expensive?

At the moment it’s only one sprite in the game that needs to be coded this way, but I’d like to unify the code as much as possible, meaning many, many sprites will work this way.

From looking around it looks as if I can either create a Render Target, or copy the data with SetData.

Do you folks have any views on which way to go? I need to contain the code in the child class otherwise the parent class is going to get out of control!

Thanks.

Why would it be impracticable for the base-class to hold a Texture2D[] and a current-item-pointer?
In case of a single sheet the child-class just wouldn’t advance the item-pointer and leave it at zero…
The base-class implementation of the sprite draws Texture2D[current-item-pointer] with the given coordinates (source and dest)…
Or maybe I don’t get your question.

You’re dealing with instances of such classes later on. So every instance you create will hold its own Texture2D. Regardless of it being stored in the base- or child-class. But as long as you loaded it using the content-manager there will be only a single in-memory representation of it anyway. So no harm done.

If you’d use get- and set-data you’ll be responsible for disposing the textures and you will have duplicate in-memory-representations of those textures (or you’ll have to de-duplicate them yourself)… I wouldn’t do that.