Sprite sheet class best practice?

Hi folks.

I’ve decided, after a LOT of deliberation to go with the Sprite Sheet approach to displaying a tumbling 3d object. I will investigate the other options at another time, only if for the fun of learning.

I’m now writing a class to contain the sprite sheet and return a single sprite when needed. What’s the best practice for returning the part graphic required? I’ve seen examples where the class is a simple container for location reference and the rectangle is handled in the main draw routine, but I’d sooner have a completely self contained class which just returns the part of the graphic needed at draw time.

But If I go this way I need a pixel copy for the returned rectangle. This seems rather expensive. Is there a better way?

Thanks.

You can just return the texture and the rectangle out of it that contains the frame you want to draw. Then use a SpriteBatch.Draw overload that takes a source rectangle and set that to the rectangle with the frame. There’s no need for a copy operation this way.