Class SpriteMapBuilder<T>
Definition
Namespace: StardewUI.Graphics
Assembly: StardewUI.dll
Builder interface for a SpriteMap<T> using a single texture source.
Type Parameters
T
Type of key for which to obtain sprites.
Inheritance
Object ⇦ SpriteMapBuilder<T>
Remarks
Works by maintaining a virtual "cursor" which can be moved to capture the next sprite, and adding either one sprite at a time with a specific size, or several with the same size, wrapping around when necessary.
Members
Constructors
Name | Description |
---|---|
SpriteMapBuilder<T>(Texture2D) | Builder interface for a SpriteMap<T> using a single texture source. |
Methods
Name | Description |
---|---|
Add(T, Int32?, Int32?) | Adds a single sprite. |
Add(T, Rectangle) | Adds a sprite using its specific position and size in the texture. |
Add(IEnumerable<T>) | Adds a sequence of sprites, starting from the current cursor position and using the most recently configured Size(Int32, Int32) and Padding(Int32, Int32) to advance the cursor after each element. |
Add(T) | Adds a sequence of sprites, starting from the current cursor position and using the most recently configured Size(Int32, Int32) and Padding(Int32, Int32) to advance the cursor after each element. |
Build() | Builds a new SpriteMap<T> from the registered sprites. |
Default(T) | Configures the default sprite for unknown keys to use an existing sprite that has already been registered. |
Default(Sprite) | Configures the default sprite for unknown keys to use a custom sprite. |
MoveBy(Int32, Int32) | Moves the current cursor position by a specified offset. |
MoveBy(Point) | Moves the current cursor position by a specified offset. |
MoveTo(Int32, Int32) | Moves the cursor to a specific coordinate. |
MoveTo(Point) | Moves the cursor to a specific coordinate. |
Padding(Int32, Int32) | Configures the padding between sprites. |
Padding(Point) | Configures the padding between sprites. |
Size(Int32, Int32) | Configures the pixel size per sprite. |
Size(Point) | Configures the pixel size per sprite. |
Details
Constructors
SpriteMapBuilder<T>(Texture2D)
Builder interface for a SpriteMap<T> using a single texture source.
Parameters
texture
Texture2D
Remarks
Works by maintaining a virtual "cursor" which can be moved to capture the next sprite, and adding either one sprite at a time with a specific size, or several with the same size, wrapping around when necessary.
Methods
Add(T, int?, int?)
Adds a single sprite.
Parameters
key
T
The key for the sprite.
width
Nullable<Int32>
Optional override width, otherwise the most recent Size(Int32, Int32) will be used. Custom widths only apply to this sprite and will not affect the size of any subsequent additions.
height
Nullable<Int32>
Optional override height, otherwise the most recent Size(Int32, Int32) will be used. Custom heights only apply to this sprite and will not affect the size of any subsequent additions.
Returns
The current builder instance.
Add(T, Rectangle)
Adds a sprite using its specific position and size in the texture.
public StardewUI.Graphics.SpriteMapBuilder<T> Add(T key, Microsoft.Xna.Framework.Rectangle sourceRect);
Parameters
key
T
The key for the sprite.
sourceRect
Rectangle
The exact position and size of the sprite.
Returns
The current builder instance.
Remarks
After adding, moves the cursor to the top-right of the sourceRect
, unless it would be horizontally out of bounds, in which case it wraps to the beginning (X = 0) of the next row.
Add(IEnumerable<T>)
Adds a sequence of sprites, starting from the current cursor position and using the most recently configured Size(Int32, Int32) and Padding(Int32, Int32) to advance the cursor after each element.
Parameters
keys
IEnumerable<T>
The keys for the sprites to add, in the same left-to-right order that they appear in the source texture.
Returns
The current builder instance.
Remarks
Wraps to the beginning of the next row (X = 0) when the end of a row is reached.
Add(T)
Adds a sequence of sprites, starting from the current cursor position and using the most recently configured Size(Int32, Int32) and Padding(Int32, Int32) to advance the cursor after each element.
Parameters
keys
T
The keys for the sprites to add, in the same left-to-right order that they appear in the source texture.
Returns
The current builder instance.
Remarks
Wraps to the beginning of the next row (X = 0) when the end of a row is reached.
Build()
Builds a new SpriteMap<T> from the registered sprites.
Returns
Default(T)
Configures the default sprite for unknown keys to use an existing sprite that has already been registered.
Parameters
key
T
Key of the previously-added sprite to use as default.
Returns
The current builder instance.
Default(Sprite)
Configures the default sprite for unknown keys to use a custom sprite.
Parameters
sprite
Sprite
The sprite to use as default.
Returns
The current builder instance.
MoveBy(int, int)
Moves the current cursor position by a specified offset.
Parameters
x
Int32
Horizontal offset from current position.
y
Int32
Vertical offset from current position.
Returns
The current builder instance.
MoveBy(Point)
Moves the current cursor position by a specified offset.
Parameters
p
Point
The horizontal (X) and vertical (Y) offsets from the current position.
Returns
The current builder instance.
MoveTo(int, int)
Moves the cursor to a specific coordinate.
Parameters
x
Int32
The new X coordinate of the cursor.
y
Int32
The new Y coordinate of the cursor.
Returns
The current builder instance.
Remarks
Generally used when dealing with semi-regular spritesheets having distinct areas that are individually uniform but different from each other, e.g. a row of 10x10 placed in an empty area of a 32x32 sheet.
MoveTo(Point)
Moves the cursor to a specific coordinate.
Parameters
p
Point
The horizontal (X) and vertical (Y) coordinates for the cursor.
Returns
The current builder instance.
Remarks
Generally used when dealing with semi-regular spritesheets having distinct areas that are individually uniform but different from each other, e.g. a row of 10x10 placed in an empty area of a 32x32 sheet.
Padding(int, int)
Configures the padding between sprites.
Parameters
x
Int32
Horizontal padding from the right edge of one sprite to the left edge of the next. Added whenever advancing from left to right.
y
Int32
Vertical padding from the bottom edge of one sprite to the top edge of the next. Added whenever wrapping from the end of a row to the beginning of the next row.
Returns
The current builder instance.
Remarks
Applies only to new sprites added afterward; will not affect sprites previously added.
Padding(Point)
Configures the padding between sprites.
Parameters
p
Point
A point containing the horizontal (X) and vertical (Y) padding values. See Padding(Int32, Int32).
Returns
The current builder instance.
Remarks
Applies only to new sprites added afterward; will not affect sprites previously added.
Size(int, int)
Configures the pixel size per sprite.
Parameters
width
Int32
The pixel width for newly-added sprites.
height
Int32
The pixel height for newly-added sprites.
Returns
The current builder instance.
Remarks
Applies only to new sprites added afterward; will not affect sprites previously added.
Size(Point)
Configures the pixel size per sprite.
Parameters
p
Point
A point containing the width (X) and height (Y) for newly-added sprites.
Returns
The current builder instance.
Remarks
Applies only to new sprites added afterward; will not affect sprites previously added.