Gondwana Game Engine
Gondwana is a cross-platform 2.5D game and rendering engine written in C#/.NET 8. It provides fine-grained control over rendering, timing, and scene composition, with built-in support for parallax, z-ordering, pixel overhang, collision detection, and particle effects. Gondwana targets desktop, mobile, and web platforms using SkiaSharp for graphics and NAudio for sound.
Loading...
Searching...
No Matches
Gondwana.Drawing.Tilesheets.Tilesheet Class Referencesealed

Represents a tilesheet image and metadata for rendering tiles. More...

Inheritance diagram for Gondwana.Drawing.Tilesheets.Tilesheet:

Public Member Functions

 Tilesheet (string name, SKBitmap bitmap)
 Initializes a new instance of the Tilesheet class with the specified name and bitmap.
 Tilesheet (string name, Stream stream)
 Initializes a new instance of the Tilesheet class by loading an image from a stream.
 Tilesheet (string name, string file)
 Initializes a new instance of the Tilesheet class by loading an image from a file.
 Tilesheet (AssetsFile resFile, string entryName)
 Initializes a new instance of the Tilesheet class by loading an image from an assets file.
 Tilesheet (Tilesheet baseSheet, string name, string file)
 Initializes a new instance of the Tilesheet class by copying settings from a base tilesheet and loading a new image from a file.
void ApplyMask (SKColor? maskColor=null, byte tolerance=5)
 Applies an alpha mask to the tilesheet, making pixels matching the specified color transparent, and then premultiplies the alpha channel.
void ApplyPremultiplyAlpha ()
 Premultiplies the alpha channel of the bitmap, improving rendering performance and quality. Preserves the original bitmap in SkBitmapOriginal before applying the operation.
byte[] ToByteArray (SKEncodedImageFormat format=SKEncodedImageFormat.Png, int quality=100)
 Encodes the tilesheet bitmap to a byte array in the specified image format.
SKImage? GetImage (int x, int y)
 Retrieves the SkiaSharp image for the tile at the specified coordinates.
SKBitmap? GetBitmap (int x, int y)
 Retrieves the SkiaSharp bitmap for the tile at the specified coordinates.
Dictionary<(int x, int y), SKBitmap > GetAllBitmaps ()
 Retrieves all tile bitmaps from the tilesheet as a dictionary indexed by their coordinates.
Dictionary<(int x, int y), SKImage > GetAllImages ()
 Retrieves all tile images from the tilesheet as a dictionary indexed by their coordinates.
void Dispose ()
 Releases all resources used by this tilesheet, including cached tiles, bitmaps, and registration in the TilesheetRegistry.

Properties

SKBitmap SkBitmap [get]
 Gets the SkiaSharp bitmap containing the tilesheet image. This may be a modified version if alpha masking or premultiplication has been applied.
SKBitmap? SkBitmapOriginal = null [get]
 Gets the original SkiaSharp bitmap before any alpha masking or premultiplication was applied. Returns null if no modifications have been made.
string Name [get, set]
 Gets or sets the name of this tilesheet. Changing the name updates the tilesheet's registration in the TilesheetRegistry.
Size TileSize [get, set]
 Gets or sets the size of each individual tile in the tilesheet (without overhang). Setting this property rebuilds the internal tile cache.
Overhang OverhangPixels = Overhang.None [get, set]
 Gets or sets the overhang dimensions (in pixels) that extend beyond each tile's base boundaries.
int InitialOffsetX [get, set]
 Gets or sets the horizontal offset (in pixels) from the left edge of the tilesheet to the first tile. Setting this property rebuilds the internal tile cache.
int InitialOffsetY [get, set]
 Gets or sets the vertical offset (in pixels) from the top edge of the tilesheet to the first tile. Setting this property rebuilds the internal tile cache.
int XPixelsBetweenTiles [get, set]
 Gets or sets the horizontal spacing (in pixels) between tiles in the tilesheet. Setting this property rebuilds the internal tile cache.
int YPixelsBetweenTiles [get, set]
 Gets or sets the vertical spacing (in pixels) between tiles in the tilesheet. Setting this property rebuilds the internal tile cache.
TypedValueBag ValueBag = new() [get, set]
 Gets or sets the value bag for storing arbitrary typed values associated with this tilesheet.
AssetsFileIdentifierAssetIdentifier [get]
 Gets the asset identifier if this tilesheet was loaded from an assets file. Returns null if the tilesheet was loaded from another source.
string ImageFilePath = string.Empty [get]
 Gets the file path of the image file if this tilesheet was loaded from a file. Returns an empty string if the tilesheet was loaded from another source.
SKColor? MaskColor = null [get]
 Gets the color used for alpha masking, if ApplyMask has been called. Returns null if no mask has been applied.
byte MaskTolerance = 5 [get]
 Gets the tolerance value used when applying the alpha mask. This determines how closely pixels must match the mask color to be made transparent.
bool Premultiplied = false [get]
 Gets a value indicating whether the bitmap has been premultiplied with its alpha channel. This is true after calling ApplyMask or ApplyPremultiplyAlpha.
Frame this[int x, int y] [get]
 Returns a Frame representing the tile at the given sheet coordinates.

Events

EventHandler< TilesheetDisposedEventArgsDisposed
 Occurs when this tilesheet is disposed.

Detailed Description

Represents a tilesheet image and metadata for rendering tiles.

Constructor & Destructor Documentation

◆ Tilesheet() [1/5]

Gondwana.Drawing.Tilesheets.Tilesheet.Tilesheet ( string name,
SKBitmap bitmap )

Initializes a new instance of the Tilesheet class with the specified name and bitmap.

Parameters
nameThe name to assign to this tilesheet.
bitmapThe SkiaSharp bitmap containing the tilesheet image.

◆ Tilesheet() [2/5]

Gondwana.Drawing.Tilesheets.Tilesheet.Tilesheet ( string name,
Stream stream )

Initializes a new instance of the Tilesheet class by loading an image from a stream.

Parameters
nameThe name to assign to this tilesheet.
streamThe stream containing the image data.
Exceptions
ArgumentExceptionThrown when the stream contains invalid image data.

◆ Tilesheet() [3/5]

Gondwana.Drawing.Tilesheets.Tilesheet.Tilesheet ( string name,
string file )

Initializes a new instance of the Tilesheet class by loading an image from a file.

Parameters
nameThe name to assign to this tilesheet.
fileThe path to the image file.
Exceptions
ArgumentExceptionThrown when the file is not a valid image.

◆ Tilesheet() [4/5]

Gondwana.Drawing.Tilesheets.Tilesheet.Tilesheet ( AssetsFile resFile,
string entryName )

Initializes a new instance of the Tilesheet class by loading an image from an assets file.

Parameters
resFileThe assets file containing the tilesheet image.
entryNameThe name of the asset entry within the assets file.
Exceptions
ArgumentNullExceptionThrown when resFile is null.
ArgumentExceptionThrown when entryName is null or whitespace, or when the asset cannot be decoded.
InvalidOperationExceptionThrown when the asset entry does not exist or returns a null data stream.

◆ Tilesheet() [5/5]

Gondwana.Drawing.Tilesheets.Tilesheet.Tilesheet ( Tilesheet baseSheet,
string name,
string file )

Initializes a new instance of the Tilesheet class by copying settings from a base tilesheet and loading a new image from a file.

Parameters
baseSheetThe tilesheet whose settings should be copied.
nameThe name to assign to this tilesheet.
fileThe path to the image file.

Member Function Documentation

◆ ApplyMask()

void Gondwana.Drawing.Tilesheets.Tilesheet.ApplyMask ( SKColor? maskColor = null,
byte tolerance = 5 )

Applies an alpha mask to the tilesheet, making pixels matching the specified color transparent, and then premultiplies the alpha channel.

Parameters
maskColorThe color to treat as transparent. If null, defaults to white.
toleranceThe tolerance for color matching (0-255). Lower values require closer matches.
Exceptions
ArgumentExceptionThrown when the bitmap is null or empty.

◆ ApplyPremultiplyAlpha()

void Gondwana.Drawing.Tilesheets.Tilesheet.ApplyPremultiplyAlpha ( )

Premultiplies the alpha channel of the bitmap, improving rendering performance and quality. Preserves the original bitmap in SkBitmapOriginal before applying the operation.

Exceptions
ArgumentExceptionThrown when the bitmap is null or empty.

◆ Dispose()

void Gondwana.Drawing.Tilesheets.Tilesheet.Dispose ( )

Releases all resources used by this tilesheet, including cached tiles, bitmaps, and registration in the TilesheetRegistry.

◆ GetAllBitmaps()

Dictionary<(int x, int y), SKBitmap > Gondwana.Drawing.Tilesheets.Tilesheet.GetAllBitmaps ( )

Retrieves all tile bitmaps from the tilesheet as a dictionary indexed by their coordinates.

Returns
A dictionary where keys are (x, y) tuples representing tile coordinates and values are the corresponding SKBitmap instances.

◆ GetAllImages()

Dictionary<(int x, int y), SKImage > Gondwana.Drawing.Tilesheets.Tilesheet.GetAllImages ( )

Retrieves all tile images from the tilesheet as a dictionary indexed by their coordinates.

Returns
A dictionary where keys are (x, y) tuples representing tile coordinates and values are the corresponding SKImage instances.

◆ GetBitmap()

SKBitmap? Gondwana.Drawing.Tilesheets.Tilesheet.GetBitmap ( int x,
int y )

Retrieves the SkiaSharp bitmap for the tile at the specified coordinates.

Parameters
xThe zero-based tile column index.
yThe zero-based tile row index.
Returns
The SKBitmap for the specified tile, or null if the coordinates are out of bounds or the tile cache is not initialized.

◆ GetImage()

SKImage? Gondwana.Drawing.Tilesheets.Tilesheet.GetImage ( int x,
int y )

Retrieves the SkiaSharp image for the tile at the specified coordinates.

Parameters
xThe zero-based tile column index.
yThe zero-based tile row index.
Returns
The SKImage for the specified tile, or null if the coordinates are out of bounds or the tile cache is not initialized.

◆ ToByteArray()

byte[] Gondwana.Drawing.Tilesheets.Tilesheet.ToByteArray ( SKEncodedImageFormat format = SKEncodedImageFormat::Png,
int quality = 100 )

Encodes the tilesheet bitmap to a byte array in the specified image format.

Parameters
formatThe image format to encode to. Defaults to PNG.
qualityThe encoding quality (0-100). Defaults to 100 (highest quality).
Returns
A byte array containing the encoded image data.
Exceptions
ArgumentExceptionThrown when the bitmap is null or empty.

Property Documentation

◆ AssetIdentifier

AssetsFileIdentifier? Gondwana.Drawing.Tilesheets.Tilesheet.AssetIdentifier
get

Gets the asset identifier if this tilesheet was loaded from an assets file. Returns null if the tilesheet was loaded from another source.

◆ ImageFilePath

string Gondwana.Drawing.Tilesheets.Tilesheet.ImageFilePath = string.Empty
get

Gets the file path of the image file if this tilesheet was loaded from a file. Returns an empty string if the tilesheet was loaded from another source.

◆ InitialOffsetX

int Gondwana.Drawing.Tilesheets.Tilesheet.InitialOffsetX
getset

Gets or sets the horizontal offset (in pixels) from the left edge of the tilesheet to the first tile. Setting this property rebuilds the internal tile cache.

◆ InitialOffsetY

int Gondwana.Drawing.Tilesheets.Tilesheet.InitialOffsetY
getset

Gets or sets the vertical offset (in pixels) from the top edge of the tilesheet to the first tile. Setting this property rebuilds the internal tile cache.

◆ MaskColor

SKColor? Gondwana.Drawing.Tilesheets.Tilesheet.MaskColor = null
get

Gets the color used for alpha masking, if ApplyMask has been called. Returns null if no mask has been applied.

◆ MaskTolerance

byte Gondwana.Drawing.Tilesheets.Tilesheet.MaskTolerance = 5
get

Gets the tolerance value used when applying the alpha mask. This determines how closely pixels must match the mask color to be made transparent.

◆ Name

string Gondwana.Drawing.Tilesheets.Tilesheet.Name
getset

Gets or sets the name of this tilesheet. Changing the name updates the tilesheet's registration in the TilesheetRegistry.

◆ OverhangPixels

Overhang Gondwana.Drawing.Tilesheets.Tilesheet.OverhangPixels = Overhang.None
getset

Gets or sets the overhang dimensions (in pixels) that extend beyond each tile's base boundaries.

◆ Premultiplied

bool Gondwana.Drawing.Tilesheets.Tilesheet.Premultiplied = false
get

Gets a value indicating whether the bitmap has been premultiplied with its alpha channel. This is true after calling ApplyMask or ApplyPremultiplyAlpha.

◆ SkBitmap

SKBitmap Gondwana.Drawing.Tilesheets.Tilesheet.SkBitmap
get

Gets the SkiaSharp bitmap containing the tilesheet image. This may be a modified version if alpha masking or premultiplication has been applied.

◆ SkBitmapOriginal

SKBitmap? Gondwana.Drawing.Tilesheets.Tilesheet.SkBitmapOriginal = null
get

Gets the original SkiaSharp bitmap before any alpha masking or premultiplication was applied. Returns null if no modifications have been made.

◆ this[int x, int y]

Frame Gondwana.Drawing.Tilesheets.Tilesheet.this[int x, int y]
get

Returns a Frame representing the tile at the given sheet coordinates.

Parameters
xZero-based tile column index.
yZero-based tile row index.

◆ TileSize

Size Gondwana.Drawing.Tilesheets.Tilesheet.TileSize
getset

Gets or sets the size of each individual tile in the tilesheet (without overhang). Setting this property rebuilds the internal tile cache.

◆ ValueBag

TypedValueBag Gondwana.Drawing.Tilesheets.Tilesheet.ValueBag = new()
getset

Gets or sets the value bag for storing arbitrary typed values associated with this tilesheet.

◆ XPixelsBetweenTiles

int Gondwana.Drawing.Tilesheets.Tilesheet.XPixelsBetweenTiles
getset

Gets or sets the horizontal spacing (in pixels) between tiles in the tilesheet. Setting this property rebuilds the internal tile cache.

◆ YPixelsBetweenTiles

int Gondwana.Drawing.Tilesheets.Tilesheet.YPixelsBetweenTiles
getset

Gets or sets the vertical spacing (in pixels) between tiles in the tilesheet. Setting this property rebuilds the internal tile cache.

Event Documentation

◆ Disposed

EventHandler<TilesheetDisposedEventArgs> Gondwana.Drawing.Tilesheets.Tilesheet.Disposed

Occurs when this tilesheet is disposed.