I have a sprite that I use as a sprite sheet, where regions of the image represent various UI elements (window corner, border, background, etc.).
I want to use a certain region of that sprite as a texture that I can tile over a larger destination rectangle.
Setting the SamplerState to LinearWrap and then calling SpriteBatch.Draw with destination rect and source rect ends up stretching that region of the image, not tiling it.
All the examples I've seen that implement tiling use the entire sprite - I only want to use a region of it, and tile that region.
Is there any way to do this?
Edit for clarity:
Here's an example spritesheet
where I want that colored region. I have a rectangle that represents a window border, that is larger than the region in the source image.
Here's what I want to end up with
Here's the code I've been using.
spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.LinearWrap, null, null); spriteBatch.Draw(sourceTexture, windowTopBorderRect, sourceTextureRegionRect, Color.White, 0, Vector2.Zero, SpriteEffects.None, 0);
And what I get is the image stretched across the window border rectangle, instead of tiling the source region within that rectangle.