I have an image, let’s says a .png, that is uploaded by the user.
This image has a fixed size, let’s say 100×100.
I would like to create 4 sprites with this image.
One from (0,0) to (50,50)
Another from (50, 0) to (100, 50)
The third from (0, 50) to (50, 100)
The last from (50, 50) to (100, 100)
How can I do that with my prefered C# ?
Thanks in advance for any help
To create a texture from a PNG file, use the
Texture2D.FromStream()method (MSDN).To draw the different sections of the texture, use the
sourceRectangleparameter to an overload ofSpriteBatch.Drawthat accepts it (MSDN).Here’s some example code: