NineSliceRuntime
Last updated
Was this helpful?
Last updated
Was this helpful?
The NineSliceRuntime object is used to draw a visual object which references a Texture2D, but which does not stretch the corner pieces of a texture, and which only stretches the edges between the corners along their axis. In other words, the NineSlice (sometimes also referred to as a sprite frame) is used to draw frames in UI which can stretch without introducing visual artifacts.
For more information about the NineSlice type, see the .
The following code can be used to instantiate a NineSliceRuntime which uses a Texture (png file) named Frame.png.
NineSlice textures can be assigned using a string property or Texture2D instance. When assigning using a string, the ToolsUtilities.FileManager.RelativeDirectory
is used to determine the file's directory.
For example, consider a file called Frame.png which is located in the Content directory:
This file can be used as a texture by assigning the RelativeDirectory and then loading Frame.png. Note that RelativeDirectory is usually set to Content, or to the location of the .gumx file.
Alternatively, a Texture2D can be assigned directly
Once a SourceFileName is assigned, the SourceFile property references a valid Texture2D which can be reused.
By default a NineSlice uses it entire texture. This can be customized using texture coordinate and TextureAddress properies as shown in the following code:
Note that if TextureAddress isn't set to Custom, then the four coordinate values are ignored and the entire texture is used.