How To: Tile a Sprite
This sample takes advantage of the texture addressing modes of the graphics card to duplicate a texture across the area defined for drawing by SpriteBatch.Draw. Using SpriteSortMode.Immediate allows us to set the TextureAddressMode directly and enable wrapping. Other address modes (such as mirroring) can create interesting results.
The Complete Sample
The code in this topic shows you the technique. You can download a complete code sample for this topic, including full source code and any additional supporting files required by the sample.
Drawing a Tiled Sprite
To draw a tiled sprite on screen
- Follow the procedures of How To: Draw a Sprite.
The total width of the Rectangle should be the number of times to tile your sprite in the x direction multiplied by the width of the sprite. The total height of the Rectangle should be the number of times to tile your sprite in the y direction multiplied by the height of the sprite.
- Call SpriteBatch.Draw with the sprite to tile, the starting position of the sprite, the source rectangle you created, and other relevant parameters.
- When all of the sprites have been drawn, call End on your SpriteBatch object.