The SpriteRuntime object can be used to draw a Texture2D to screen. It supports drawing the entire texture or a portion. It also provides the ability to scale according to the source texture size and aspect ratio.
The following code can be used to instantiate a Sprite which uses a Texture (png file) named BearTexture.png.
A SpriteRuntime's texture can be assigned using the name of the file or a direct Texture2D reference.
The SourceFileName property is used to assign the SpriteRuntime's texture using a file name. The name of the file should (by default) be relative to the Content folder. For example, consider the following line:
This code assumes that the file is relative to the project's Content folder, as shown in the following screenshot:
For more information on working with files at runtime, see the File Loading page.
Assigning Texture
If your game manages its own textures, you can assign a Texture on the SpriteRuntime through its Texture property as shown in the following code.
Note that assigning the SourceFileName property results in the Texture property referencing a texture if a valid texture is found.