GameTexture Class
Definition
Section titled “Definition”Creates a Microsoft.Xna.Framework.Graphics.Texture2D. Generally you request this from the GetTexture(string) method.
public class GameTexture : ITexture, IDisposableInheritance object
Implements ITexture, IDisposable
Constructors
Section titled “Constructors”GameTexture(string)
Section titled “GameTexture(string)”Loads a Microsoft.Xna.Framework.Graphics.Texture2D from a file path.
public GameTexture(string path)Parameters
Section titled “Parameters”path string
GameTexture(Stream)
Section titled “GameTexture(Stream)”Loads a Microsoft.Xna.Framework.Graphics.Texture2D from a stream.
public GameTexture(Stream stream)Parameters
Section titled “Parameters”stream Stream
The stream containing the texture data.
GameTexture(int, int)
Section titled “GameTexture(int, int)”Creates a new game texture with the specified width and height.
public GameTexture(int width, int height)Parameters
Section titled “Parameters”width int
The width of the texture in pixels.
height int
The height of the texture in pixels.
GameTexture(int, int, Color[])
Section titled “GameTexture(int, int, Color[])”Creates a new game texture with the specified width, height, and pixels.
public GameTexture(int width, int height, Color[] pixels)Parameters
Section titled “Parameters”width int
The width of the texture in pixels.
height int
The height of the texture in pixels.
pixels SadRogue.Primitives.Color[]
The pixels to create the texture from. The array must be width * height.
GameTexture(Texture2D, bool)
Section titled “GameTexture(Texture2D, bool)”Wraps an existing texture.
public GameTexture(Texture2D texture, bool handleDispose = false)Parameters
Section titled “Parameters”texture Microsoft.Xna.Framework.Graphics.Texture2D
The texture being wrapped by this object.
handleDispose bool
When true, disposing this object will dispose the texture.
Properties
Section titled “Properties”Texture
Section titled “Texture”public Texture2D Texture { get; }ResourcePath
Section titled “ResourcePath”The file path to the texture.
public string ResourcePath { get; }Height
Section titled “Height”The height of the texture.
public int Height { get; }The width of the texture.
public int Width { get; }Size of the texture. Generally, the count of pixels.
public int Size { get; }Methods
Section titled “Methods”Dispose()
Section titled “Dispose()”Disposes the underlaying texture object and releases reference to it.
public void Dispose()GetPixels()
Section titled “GetPixels()”Gets an array of colors. Row-major ordered.
public Color[] GetPixels()Returns
Section titled “Returns”SadRogue.Primitives.Color[]
The pixels. Row-major ordered.
GetPixelsMonoColor()
Section titled “GetPixelsMonoColor()”Gets an array of Microsoft.Xna.Framework.Color pixels.
public Color[] GetPixelsMonoColor()Returns
Section titled “Returns”Microsoft.Xna.Framework.Color[]
An array of pixels. Row-major ordered.
SetPixels(Color[])
Section titled “SetPixels(Color[])”Sets colors in the texture from an array of pixels. Row-major ordered.
public void SetPixels(Color[] pixels)Parameters
Section titled “Parameters”pixels SadRogue.Primitives.Color[]
The individual pixel colors to set. Row-major ordered.
SetPixels(ReadOnlySpan<Color>)
Section titled “SetPixels(ReadOnlySpan<Color>)”Sets colors in the texture from a span of pixels. Row-major ordered.
public void SetPixels(ReadOnlySpan<Color> pixels)Parameters
Section titled “Parameters”pixels ReadOnlySpan<Color>
The individual pixel colors to set. Row-major ordered.
SetPixels(Color[])
Section titled “SetPixels(Color[])”Replaces texture colors with the array of Microsoft.Xna.Framework.Color pixels.
public void SetPixels(Color[] pixels)Parameters
Section titled “Parameters”pixels Microsoft.Xna.Framework.Color[]
Array of Microsoft.Xna.Framework.Color pixels.
Exceptions
Section titled “Exceptions”SetPixel(Point, Color)
Section titled “SetPixel(Point, Color)”Sets a specific pixel in the texture to a color by x,y coordinate.
public void SetPixel(Point position, Color color)Parameters
Section titled “Parameters”position SadRogue.Primitives.Point
The position of the pixel to set.
color SadRogue.Primitives.Color
The color to set.
SetPixel(Point, Color)
Section titled “SetPixel(Point, Color)”Sets a single pixel in the texture to the specified Microsoft.Xna.Framework.Color at the given position.
public void SetPixel(Point position, Color color)Parameters
Section titled “Parameters”position SadRogue.Primitives.Point
Position of the pixel in the texture.
color Microsoft.Xna.Framework.Color
Color of the pixel.
SetPixel(int, Color)
Section titled “SetPixel(int, Color)”Sets a specific pixel in the texture to a color by index. Row-major ordered.
public void SetPixel(int index, Color color)Parameters
Section titled “Parameters”index int
color SadRogue.Primitives.Color
SetPixel(int, Color)
Section titled “SetPixel(int, Color)”Sets a single pixel in the texture to the specified Microsoft.Xna.Framework.Color at the given index.
public void SetPixel(int index, Color color)Parameters
Section titled “Parameters”index int
Index of the pixel.
color Microsoft.Xna.Framework.Color
Microsoft.Xna.Framework.Color of the pixel.
GetPixel(Point)
Section titled “GetPixel(Point)”Gets a pixel in the texture by x,y coordinate.
public Color GetPixel(Point position)Parameters
Section titled “Parameters”position SadRogue.Primitives.Point
The x,y coordinate of the pixel.
Returns
Section titled “Returns”SadRogue.Primitives.Color
The color of the pixel.
GetPixelMonoColor(Point)
Section titled “GetPixelMonoColor(Point)”Gets the Microsoft.Xna.Framework.Color at the given position in the texture.
public Color GetPixelMonoColor(Point position)Parameters
Section titled “Parameters”position SadRogue.Primitives.Point
Position in the texture.
Returns
Section titled “Returns”Microsoft.Xna.Framework.Color
Microsoft.Xna.Framework.Color of the pixel.
GetPixel(int)
Section titled “GetPixel(int)”Gets a pixel in the texture by index. Row-major ordered.
public Color GetPixel(int index)Parameters
Section titled “Parameters”index int
The index of the pixel.
Returns
Section titled “Returns”SadRogue.Primitives.Color
The color of the pixel.
GetPixelMonoColor(int)
Section titled “GetPixelMonoColor(int)”Gets the Microsoft.Xna.Framework.Color at the given index in the texture.
public Color GetPixelMonoColor(int index)Parameters
Section titled “Parameters”index int
Index of the pixel in the texture.
Returns
Section titled “Returns”Microsoft.Xna.Framework.Color
Microsoft.Xna.Framework.Color of the pixel.
ToSurface(TextureConvertMode, int, int, TextureConvertBackgroundStyle, TextureConvertForegroundStyle, Color[], ICellSurface)
Section titled “ToSurface(TextureConvertMode, int, int, TextureConvertBackgroundStyle, TextureConvertForegroundStyle, Color[], ICellSurface)”Converts the texture into a cell surface based on the specified mode.
public ICellSurface ToSurface(TextureConvertMode mode, int surfaceWidth, int surfaceHeight, TextureConvertBackgroundStyle backgroundStyle = TextureConvertBackgroundStyle.Pixel, TextureConvertForegroundStyle foregroundStyle = TextureConvertForegroundStyle.Block, Color[] cachedColorArray = null, ICellSurface cachedSurface = null)Parameters
Section titled “Parameters”mode TextureConvertMode
The mode used when converting the texture to a surface.
surfaceWidth int
How many cells wide the returned surface is.
surfaceHeight int
How many cells high the returned surface is.
backgroundStyle TextureConvertBackgroundStyle
The style to use when mode is Background.
foregroundStyle TextureConvertForegroundStyle
The style to use when mode is Foreground.
cachedColorArray SadRogue.Primitives.Color[]
When provided, this array is used for color data. It must match the texture’s expected GetPixels() bounds. Used with cachedColorArray.
cachedSurface ICellSurface
The cell surface to use instead of creating a new one. Used with cachedColorArray.
Returns
Section titled “Returns”ICellSurface
A new surface.