Skip to content

GameTexture Class

Creates a Microsoft.Xna.Framework.Graphics.Texture2D. Generally you request this from the GetTexture(string) method.

C#
public class GameTexture : ITexture, IDisposable

Inheritance object

Implements ITexture, IDisposable

Loads a Microsoft.Xna.Framework.Graphics.Texture2D from a file path.

C#
public GameTexture(string path)

path string

Loads a Microsoft.Xna.Framework.Graphics.Texture2D from a stream.

C#
public GameTexture(Stream stream)

stream Stream
The stream containing the texture data.

Creates a new game texture with the specified width and height.

C#
public GameTexture(int width, int height)

width int
The width of the texture in pixels.

height int
The height of the texture in pixels.

Creates a new game texture with the specified width, height, and pixels.

C#
public GameTexture(int width, int height, Color[] pixels)

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.

Wraps an existing texture.

C#
public GameTexture(Texture2D texture, bool handleDispose = false)

texture Microsoft.Xna.Framework.Graphics.Texture2D
The texture being wrapped by this object.

handleDispose bool
When true, disposing this object will dispose the texture.

C#
public Texture2D Texture { get; }

The file path to the texture.

C#
public string ResourcePath { get; }

The height of the texture.

C#
public int Height { get; }

The width of the texture.

C#
public int Width { get; }

Size of the texture. Generally, the count of pixels.

C#
public int Size { get; }

Disposes the underlaying texture object and releases reference to it.

C#
public void Dispose()

Gets an array of colors. Row-major ordered.

C#
public Color[] GetPixels()

SadRogue.Primitives.Color[]
The pixels. Row-major ordered.

Gets an array of Microsoft.Xna.Framework.Color pixels.

C#
public Color[] GetPixelsMonoColor()

Microsoft.Xna.Framework.Color[]
An array of pixels. Row-major ordered.

Sets colors in the texture from an array of pixels. Row-major ordered.

C#
public void SetPixels(Color[] pixels)

pixels SadRogue.Primitives.Color[]
The individual pixel colors to set. Row-major ordered.

Sets colors in the texture from a span of pixels. Row-major ordered.

C#
public void SetPixels(ReadOnlySpan<Color> pixels)

pixels ReadOnlySpan<Color>
The individual pixel colors to set. Row-major ordered.

Replaces texture colors with the array of Microsoft.Xna.Framework.Color pixels.

C#
public void SetPixels(Color[] pixels)

pixels Microsoft.Xna.Framework.Color[]
Array of Microsoft.Xna.Framework.Color pixels.

ArgumentOutOfRangeException

Sets a specific pixel in the texture to a color by x,y coordinate.

C#
public void SetPixel(Point position, Color color)

position SadRogue.Primitives.Point
The position of the pixel to set.

color SadRogue.Primitives.Color
The color to set.

Sets a single pixel in the texture to the specified Microsoft.Xna.Framework.Color at the given position.

C#
public void SetPixel(Point position, Color color)

position SadRogue.Primitives.Point
Position of the pixel in the texture.

color Microsoft.Xna.Framework.Color
Color of the pixel.

Sets a specific pixel in the texture to a color by index. Row-major ordered.

C#
public void SetPixel(int index, Color color)

index int

color SadRogue.Primitives.Color

Sets a single pixel in the texture to the specified Microsoft.Xna.Framework.Color at the given index.

C#
public void SetPixel(int index, Color color)

index int
Index of the pixel.

color Microsoft.Xna.Framework.Color
Microsoft.Xna.Framework.Color of the pixel.

Gets a pixel in the texture by x,y coordinate.

C#
public Color GetPixel(Point position)

position SadRogue.Primitives.Point
The x,y coordinate of the pixel.

SadRogue.Primitives.Color
The color of the pixel.

Gets the Microsoft.Xna.Framework.Color at the given position in the texture.

C#
public Color GetPixelMonoColor(Point position)

position SadRogue.Primitives.Point
Position in the texture.

Microsoft.Xna.Framework.Color
Microsoft.Xna.Framework.Color of the pixel.

Gets a pixel in the texture by index. Row-major ordered.

C#
public Color GetPixel(int index)

index int
The index of the pixel.

SadRogue.Primitives.Color
The color of the pixel.

Gets the Microsoft.Xna.Framework.Color at the given index in the texture.

C#
public Color GetPixelMonoColor(int index)

index int
Index of the pixel in the texture.

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.

C#
public ICellSurface ToSurface(TextureConvertMode mode, int surfaceWidth, int surfaceHeight, TextureConvertBackgroundStyle backgroundStyle = TextureConvertBackgroundStyle.Pixel, TextureConvertForegroundStyle foregroundStyle = TextureConvertForegroundStyle.Block, Color[] cachedColorArray = null, ICellSurface cachedSurface = null)

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.

ICellSurface
A new surface.