Show / Hide Table of Contents

Class GameTexture

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

Inheritance
object
GameTexture
Implements
ITexture
IDisposable
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: SadConsole.Host
Assembly: SadConsole.Host.MonoGame.dll
Syntax
public class GameTexture : ITexture, IDisposable

Constructors

GameTexture(Texture2D, bool)

Wraps an existing texture.

Declaration
public GameTexture(Texture2D texture, bool handleDispose = false)
Parameters
Type Name Description
Texture2D texture

The texture being wrapped by this object.

bool handleDispose

When true, disposing this object will dispose the texture.

GameTexture(Stream)

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

Declaration
public GameTexture(Stream stream)
Parameters
Type Name Description
Stream stream

The stream containing the texture data.

GameTexture(int, int)

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

Declaration
public GameTexture(int width, int height)
Parameters
Type Name Description
int width

The width of the texture in pixels.

int height

The height of the texture in pixels.

GameTexture(int, int, Color[])

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

Declaration
public GameTexture(int width, int height, Color[] pixels)
Parameters
Type Name Description
int width

The width of the texture in pixels.

int height

The height of the texture in pixels.

Color[] pixels

The pixels to create the texture from. The array must be width * height.

GameTexture(string)

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

Declaration
public GameTexture(string path)
Parameters
Type Name Description
string path

Properties

Height

The height of the texture.

Declaration
public int Height { get; }
Property Value
Type Description
int

ResourcePath

The file path to the texture.

Declaration
public string ResourcePath { get; }
Property Value
Type Description
string

Size

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

Declaration
public int Size { get; }
Property Value
Type Description
int

Texture

Declaration
public Texture2D Texture { get; }
Property Value
Type Description
Texture2D

Width

The width of the texture.

Declaration
public int Width { get; }
Property Value
Type Description
int

Methods

Dispose()

Disposes the underlaying texture object and releases reference to it.

Declaration
public void Dispose()

GetPixel(Point)

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

Declaration
public Color GetPixel(Point position)
Parameters
Type Name Description
Point position

The x,y coordinate of the pixel.

Returns
Type Description
Color

The color of the pixel.

GetPixel(int)

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

Declaration
public Color GetPixel(int index)
Parameters
Type Name Description
int index

The index of the pixel.

Returns
Type Description
Color

The color of the pixel.

GetPixelMonoColor(Point)

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

Declaration
public Color GetPixelMonoColor(Point position)
Parameters
Type Name Description
Point position

Position in the texture.

Returns
Type Description
Color

Microsoft.Xna.Framework.Color of the pixel.

GetPixelMonoColor(int)

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

Declaration
public Color GetPixelMonoColor(int index)
Parameters
Type Name Description
int index

Index of the pixel in the texture.

Returns
Type Description
Color

Microsoft.Xna.Framework.Color of the pixel.

GetPixels()

Gets an array of colors. Row-major ordered.

Declaration
public Color[] GetPixels()
Returns
Type Description
Color[]

The pixels. Row-major ordered.

GetPixelsMonoColor()

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

Declaration
public Color[] GetPixelsMonoColor()
Returns
Type Description
Color[]

An array of pixels. Row-major ordered.

SetPixel(Point, Color)

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

Declaration
public void SetPixel(Point position, Color color)
Parameters
Type Name Description
Point position

Position of the pixel in the texture.

Color color

Color of the pixel.

SetPixel(Point, Color)

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

Declaration
public void SetPixel(Point position, Color color)
Parameters
Type Name Description
Point position

The position of the pixel to set.

Color color

The color to set.

SetPixel(int, Color)

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

Declaration
public void SetPixel(int index, Color color)
Parameters
Type Name Description
int index

Index of the pixel.

Color color

Microsoft.Xna.Framework.Color of the pixel.

SetPixel(int, Color)

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

Declaration
public void SetPixel(int index, Color color)
Parameters
Type Name Description
int index
Color color

SetPixels(Color[])

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

Declaration
public void SetPixels(Color[] pixels)
Parameters
Type Name Description
Color[] pixels

Array of Microsoft.Xna.Framework.Color pixels.

Exceptions
Type Condition
ArgumentOutOfRangeException

SetPixels(Color[])

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

Declaration
public void SetPixels(Color[] pixels)
Parameters
Type Name Description
Color[] pixels

The individual pixel colors to set. Row-major ordered.

SetPixels(ReadOnlySpan<Color>)

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

Declaration
public void SetPixels(ReadOnlySpan<Color> pixels)
Parameters
Type Name Description
ReadOnlySpan<Color> pixels

The individual pixel colors to set. Row-major ordered.

ToSurface(TextureConvertMode, int, int, TextureConvertBackgroundStyle, TextureConvertForegroundStyle, Color[], ICellSurface)

Converts the texture into a cell surface based on the specified mode.

Declaration
public ICellSurface ToSurface(TextureConvertMode mode, int surfaceWidth, int surfaceHeight, TextureConvertBackgroundStyle backgroundStyle = TextureConvertBackgroundStyle.Pixel, TextureConvertForegroundStyle foregroundStyle = TextureConvertForegroundStyle.Block, Color[] cachedColorArray = null, ICellSurface cachedSurface = null)
Parameters
Type Name Description
TextureConvertMode mode

The mode used when converting the texture to a surface.

int surfaceWidth

How many cells wide the returned surface is.

int surfaceHeight

How many cells high the returned surface is.

TextureConvertBackgroundStyle backgroundStyle

The style to use when mode is Background.

TextureConvertForegroundStyle foregroundStyle

The style to use when mode is Foreground.

Color[] cachedColorArray

When provided, this array is used for color data. It must match the texture's expected GetPixels() bounds. Used with cachedColorArray.

ICellSurface cachedSurface

The cell surface to use instead of creating a new one. Used with cachedColorArray.

Returns
Type Description
ICellSurface

A new surface.

Implements

ITexture
IDisposable

Extension Methods

ExtensionsSystem.GetDebuggerDisplayValue(object)
In this article

Back to top

Back to top Generated by DocFX