Gorgon
Show / Hide Table of Contents

Class GorgonPolySpriteBuilder

A builder used to create a new GorgonPolySprite object.

Inheritance
object
GorgonPolySpriteBuilder
Implements
IGorgonFluentBuilder<GorgonPolySpriteBuilder, GorgonPolySprite>
IEnumerable<GorgonPolySpriteVertex>
IEnumerable
IGorgonGraphicsObject
Inherited Members
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
Namespace: Gorgon.Renderers
Assembly: Gorgon.Renderers.Gorgon2D.dll
Syntax
public class GorgonPolySpriteBuilder : IGorgonFluentBuilder<GorgonPolySpriteBuilder, GorgonPolySprite>, IEnumerable<GorgonPolySpriteVertex>, IEnumerable, IGorgonGraphicsObject
Remarks

Because the GorgonPolySprite cannot be created using the new keyword, this builder is used to build GorgonPolySprite objects.

The polygonal sprite created by this builder is built up by adding multiple GorgonPolySpriteVertex objects to the builder and calling the Build() method. These vertices make up the "hull" of the polygon (basically the outer shape of the polygon), which gets turned into triangles so it can be rendered by Gorgon. Vertex manipulation is not the only functionality provided by the builder, other initial values may also be assigned for the created sprite as well.

important

A minimum of 3 vertices are required to build a polygonal sprite. Attempting to do so with less will cause an exception.

This builder is not the only way to create a polygonal sprite, users can define a series of triangle vertices and indices and use Create(GorgonGraphics, IReadOnlyList<GorgonPolySpriteVertex>, IReadOnlyList<int>) on the GorgonPolySprite.

The resulting polygonal sprite from this builder implements IDisposable. Therefore, it is the user's responsibility to dispose of the object when they are done with it.

Constructors

| Edit this page View Source

GorgonPolySpriteBuilder(Gorgon2D)

Initializes a new instance of the GorgonPolySpriteBuilder class.

Declaration
public GorgonPolySpriteBuilder(Gorgon2D renderer)
Parameters
Type Name Description
Gorgon2D renderer

The renderer interface to use for building the polygon sprite.

See Also
GorgonPolySpriteVertex
GorgonPolySprite

Properties

| Edit this page View Source

Graphics

Property to return the graphics interface that built this object.

Declaration
public GorgonGraphics Graphics { get; }
Property Value
Type Description
GorgonGraphics
See Also
GorgonPolySpriteVertex
GorgonPolySprite
| Edit this page View Source

VertexCount

Property to return the number of vertices in the polysprite.

Declaration
public int VertexCount { get; }
Property Value
Type Description
int
See Also
GorgonPolySpriteVertex
GorgonPolySprite

Methods

| Edit this page View Source

AddVertex(GorgonPolySpriteVertex)

Function to add a vertex to the polysprite.

Declaration
public GorgonPolySpriteBuilder AddVertex(GorgonPolySpriteVertex vertex)
Parameters
Type Name Description
GorgonPolySpriteVertex vertex

The vertex to add.

Returns
Type Description
GorgonPolySpriteBuilder

The fluent interface for this builder.

Exceptions
Type Condition
ArgumentNullException

Thrown when the vertex is null.

See Also
GorgonPolySpriteVertex
GorgonPolySprite
| Edit this page View Source

AddVertices(IEnumerable<GorgonPolySpriteVertex>)

Function to add multiple vertices to the polysprite.

Declaration
public GorgonPolySpriteBuilder AddVertices(IEnumerable<GorgonPolySpriteVertex> vertices)
Parameters
Type Name Description
IEnumerable<GorgonPolySpriteVertex> vertices

The vertices to add.

Returns
Type Description
GorgonPolySpriteBuilder

The fluent interface for this builder.

Exceptions
Type Condition
ArgumentNullException

Thrown when the vertices is null.

See Also
GorgonPolySpriteVertex
GorgonPolySprite
| Edit this page View Source

AlphaTest(GorgonRangeF?)

Function to assign the inital alpha test value for the sprite.

Declaration
public GorgonPolySpriteBuilder AlphaTest(GorgonRangeF? alphaTest = null)
Parameters
Type Name Description
GorgonRangeF? alphaTest

[Optional] The alpha test value to assign.

Returns
Type Description
GorgonPolySpriteBuilder

The fluent interface for this builder.

Remarks

If the alphaTest value is null, then alpha testing will be turned off for the sprite.

See Also
GorgonPolySpriteVertex
GorgonPolySprite
| Edit this page View Source

Anchor(Vector2)

Function to assign anchor value to the polygon sprite.

Declaration
public GorgonPolySpriteBuilder Anchor(Vector2 anchor)
Parameters
Type Name Description
Vector2 anchor

The anchor for the sprite.

Returns
Type Description
GorgonPolySpriteBuilder

The fluent interface for this builder.

Remarks

This value is in relative unit coordinates. For example, 0.5, 0.5 would mean the center of the sprite.

See Also
GorgonPolySpriteVertex
GorgonPolySprite
| Edit this page View Source

Angle(float)

Function to assign an initial rotation value to the polygon sprite.

Declaration
public GorgonPolySpriteBuilder Angle(float degrees)
Parameters
Type Name Description
float degrees

The angle, in degrees, to rotate.

Returns
Type Description
GorgonPolySpriteBuilder

The fluent interface for this builder.

See Also
GorgonPolySpriteVertex
GorgonPolySprite
| Edit this page View Source

Build()

Function to return the object.

Declaration
public GorgonPolySprite Build()
Returns
Type Description
GorgonPolySprite

The object created or updated by this builder.

Remarks

This will return a GorgonPolySprite for use with the DrawPolygonSprite(GorgonPolySprite) method. The object returned implements IDisposable, so it is the responsibility of the user to dispose of the object when they are done with it.

warning

A polygon sprite must have a minimum of 3 vertices. If it does not, then this method will throw an exception.

Exceptions
Type Condition
GorgonException

Thrown if the polygonal sprite has less than 3 vertices.

See Also
GorgonPolySprite
Gorgon2D
| Edit this page View Source

Clear()

Function to clear the builder to a default state.

Declaration
public GorgonPolySpriteBuilder Clear()
Returns
Type Description
GorgonPolySpriteBuilder

The fluent builder interface.

See Also
GorgonPolySpriteVertex
GorgonPolySprite
| Edit this page View Source

Color(GorgonColor)

Function to assign the color for the polygon sprite.

Declaration
public GorgonPolySpriteBuilder Color(GorgonColor color)
Parameters
Type Name Description
GorgonColor color

The color to assign.

Returns
Type Description
GorgonPolySpriteBuilder

The fluent interface for this builder.

See Also
GorgonPolySpriteVertex
GorgonPolySprite
| Edit this page View Source

Flip(bool, bool)

Function to flip the texture coordinates for the polygon sprite.

Declaration
public GorgonPolySpriteBuilder Flip(bool horizontal = false, bool vertical = false)
Parameters
Type Name Description
bool horizontal

[Optional] true to flip horizontally.

bool vertical

[Optional] true to flip vertically.

Returns
Type Description
GorgonPolySpriteBuilder

The fluent interface for this builder.

See Also
GorgonPolySpriteVertex
GorgonPolySprite
| Edit this page View Source

GetEnumerator()

Returns an enumerator that iterates through the collection.

Declaration
public IEnumerator<GorgonPolySpriteVertex> GetEnumerator()
Returns
Type Description
IEnumerator<GorgonPolySpriteVertex>

An enumerator that can be used to iterate through the collection.

See Also
GorgonPolySpriteVertex
GorgonPolySprite
| Edit this page View Source

InsertVertex(int, GorgonPolySpriteVertex)

Function to insert a vertex at the specified index.

Declaration
public GorgonPolySpriteBuilder InsertVertex(int index, GorgonPolySpriteVertex vertex)
Parameters
Type Name Description
int index

The index to insert into.

GorgonPolySpriteVertex vertex

The vertex to insert.

Returns
Type Description
GorgonPolySpriteBuilder

The fluent interface for the this builder.

Exceptions
Type Condition
ArgumentNullException

Thrown when the vertex parameter is null.

See Also
GorgonPolySpriteVertex
GorgonPolySprite
| Edit this page View Source

InsertVertices(int, IEnumerable<GorgonPolySpriteVertex>)

Function to insert multiple vertices at the specified index.

Declaration
public GorgonPolySpriteBuilder InsertVertices(int index, IEnumerable<GorgonPolySpriteVertex> vertices)
Parameters
Type Name Description
int index

The index to insert into.

IEnumerable<GorgonPolySpriteVertex> vertices

The vertices to insert.

Returns
Type Description
GorgonPolySpriteBuilder

The fluent interface for the this builder.

Exceptions
Type Condition
ArgumentNullException

Thrown when the vertices parameter is null.

See Also
GorgonPolySpriteVertex
GorgonPolySprite
| Edit this page View Source

MoveVertex(GorgonPolySpriteVertex, int)

Function to move the specified vertex to a new location in the list.

Declaration
public GorgonPolySpriteBuilder MoveVertex(GorgonPolySpriteVertex vertex, int newIndex)
Parameters
Type Name Description
GorgonPolySpriteVertex vertex

The vertex to move.

int newIndex

The new index for the vertex.

Returns
Type Description
GorgonPolySpriteBuilder

The fluent interface for the this builder.

Exceptions
Type Condition
ArgumentNullException

Thrown when the vertex parameter is null.

See Also
GorgonPolySpriteVertex
GorgonPolySprite
| Edit this page View Source

MoveVertex(int, int)

Function to move the vertex at the specified index to a new location in the list.

Declaration
public GorgonPolySpriteBuilder MoveVertex(int oldIndex, int newIndex)
Parameters
Type Name Description
int oldIndex

The index of the vertex to move.

int newIndex

The new index for the vertex.

Returns
Type Description
GorgonPolySpriteBuilder

The fluent interface for the this builder.

See Also
GorgonPolySpriteVertex
GorgonPolySprite
| Edit this page View Source

Position(Vector2, float)

Function to assign an initial position to the polygon sprite.

Declaration
public GorgonPolySpriteBuilder Position(Vector2 position, float depth = 0)
Parameters
Type Name Description
Vector2 position

The position of the sprite.

float depth

[Optional] A depth value for the sprite.

Returns
Type Description
GorgonPolySpriteBuilder

The fluent interface for this builder.

See Also
GorgonPolySpriteVertex
GorgonPolySprite
| Edit this page View Source

RemoveVertex(GorgonPolySpriteVertex)

Function to remove a vertex from the polysprite.

Declaration
public GorgonPolySpriteBuilder RemoveVertex(GorgonPolySpriteVertex vertex)
Parameters
Type Name Description
GorgonPolySpriteVertex vertex

The vertex to remove.

Returns
Type Description
GorgonPolySpriteBuilder

The fluent interface for this builder.

Exceptions
Type Condition
ArgumentNullException

Thrown when the vertex is null.

See Also
GorgonPolySpriteVertex
GorgonPolySprite
| Edit this page View Source

RemoveVertex(int)

Function to remove a vertex from the polysprite.

Declaration
public GorgonPolySpriteBuilder RemoveVertex(int index)
Parameters
Type Name Description
int index

The index of the vertex to remove.

Returns
Type Description
GorgonPolySpriteBuilder

The fluent interface for this builder.

Exceptions
Type Condition
IndexOutOfRangeException

Thrown when the index is less than 0, or equal to/greater than the VertexCount.

See Also
GorgonPolySpriteVertex
GorgonPolySprite
| Edit this page View Source

RemoveVertices(int, int)

Function to remove multiple vertices from the polysprite.

Declaration
public GorgonPolySpriteBuilder RemoveVertices(int start, int count)
Parameters
Type Name Description
int start

The starting index to use.

int count

The number of indices to remove.

Returns
Type Description
GorgonPolySpriteBuilder

The fluent interface for this builder.

Exceptions
Type Condition
IndexOutOfRangeException

Thrown when the start is less than 0, or greater than/equal to VertexCount.

See Also
GorgonPolySpriteVertex
GorgonPolySprite
| Edit this page View Source

ResetTo(GorgonPolySprite)

Function to reset the builder to the specified object state.

Declaration
public GorgonPolySpriteBuilder ResetTo(GorgonPolySprite builderObject = null)
Parameters
Type Name Description
GorgonPolySprite builderObject

[Optional] The specified object state to copy.

Returns
Type Description
GorgonPolySpriteBuilder

The fluent builder interface.

See Also
GorgonPolySpriteVertex
GorgonPolySprite
| Edit this page View Source

Scale(Vector2)

Function to assign an initial scale to the polygon sprite.

Declaration
public GorgonPolySpriteBuilder Scale(Vector2 scale)
Parameters
Type Name Description
Vector2 scale

The scale to assign to the polygon sprite.

Returns
Type Description
GorgonPolySpriteBuilder

The fluent interface for this builder.

See Also
GorgonPolySpriteVertex
GorgonPolySprite
| Edit this page View Source

Texture(GorgonTexture2DView)

Function to assign a texture to the polygon sprite.

Declaration
public GorgonPolySpriteBuilder Texture(GorgonTexture2DView texture)
Parameters
Type Name Description
GorgonTexture2DView texture

The texture to assign to the sprite.

Returns
Type Description
GorgonPolySpriteBuilder

The fluent interface for this builder.

See Also
GorgonPolySpriteVertex
GorgonPolySprite
| Edit this page View Source

TextureArrayIndex(int)

Function to assign an array index for a texture array to the polygon sprite.

Declaration
public GorgonPolySpriteBuilder TextureArrayIndex(int textureArrayIndex)
Parameters
Type Name Description
int textureArrayIndex

The texture array index to assign.

Returns
Type Description
GorgonPolySpriteBuilder

The fluent interface for this builder.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown when the textureArrayIndex is less than 0, or greater than or equal to MaxTextureArrayCount.

See Also
GorgonPolySpriteVertex
GorgonPolySprite
| Edit this page View Source

TextureCoordinate(int, Vector2)

Function to assign a texture coordinate to a vertex at the specified index.

Declaration
public GorgonPolySpriteBuilder TextureCoordinate(int index, Vector2 textureCoordinate)
Parameters
Type Name Description
int index

The index of the vertex to update.

Vector2 textureCoordinate

The texture coordinate to assign.

Returns
Type Description
GorgonPolySpriteBuilder

The fluent interface for this builder.

Exceptions
Type Condition
IndexOutOfRangeException

Thrown when the index is less than 0, or equal to/greater than the VertexCount.

See Also
GorgonPolySpriteVertex
GorgonPolySprite
| Edit this page View Source

TextureSampler(GorgonSamplerState)

Function to assign a texture sampler to the polygon sprite.

Declaration
public GorgonPolySpriteBuilder TextureSampler(GorgonSamplerState sampler)
Parameters
Type Name Description
GorgonSamplerState sampler

The sampler to assign to the sprite.

Returns
Type Description
GorgonPolySpriteBuilder

The fluent interface for this builder.

See Also
GorgonPolySpriteVertex
GorgonPolySprite
| Edit this page View Source

TextureTransform(Vector2, Vector2)

Function to assign the transformation to apply to a texture on the sprite.

Declaration
public GorgonPolySpriteBuilder TextureTransform(Vector2 textureOffset, Vector2 textureScale)
Parameters
Type Name Description
Vector2 textureOffset

The translation amount to apply to the UV coordinates of the vertices in the polygon sprite.

Vector2 textureScale

The scale amount to apply to the UV coordinates of the vertices in the polygon sprite.

Returns
Type Description
GorgonPolySpriteBuilder

The fluent interface for this builder.

See Also
GorgonPolySpriteVertex
GorgonPolySprite

Implements

IGorgonFluentBuilder<TB, TBo>
IEnumerable<T>
IEnumerable
IGorgonGraphicsObject

Extension Methods

GorgonDebugExtensions.ValidateObject<T>(T, string)
GorgonTreeLinqExtensions.TraverseDepthFirst<T>(IEnumerable<T>, Func<T, IEnumerable<T>>)
GorgonTreeLinqExtensions.Traverse<T>(IEnumerable<T>, Func<T, IEnumerable<T>>)
GorgonNullExtensions.AsNullable<T>(object)
GorgonNullExtensions.IfNull<T>(object, T)
GorgonNullExtensions.IsNull(object)

See Also

GorgonPolySpriteVertex
GorgonPolySprite
  • Edit this page
  • View Source
In this article
Back to top Copyright 2023 - Licensed under the MIT license by Michael Winsor (Tape_Worm).
Send comments on this topic to the author