Class GorgonPolySprite
A class that defines a polygonal region to display a 2D image.
Implements
Inherited Members
Namespace: Gorgon.Renderers
Assembly: Gorgon.Renderers.Gorgon2D.dll
Syntax
public class GorgonPolySprite : IDisposable
Properties
| Edit this page View SourceAlphaTest
Property to set or return the alpha testing values.
Declaration
public GorgonRangeF? AlphaTest { get; set; }
Property Value
Type | Description |
---|---|
GorgonRangeF? |
Remarks
Alpha testing will skip rendering pixels based on the current alpha value for the pixel if it falls into the range specified by this property.
To disable alpha testing outright, set this property to null.
Anchor
Property to set or return the point around which the sprite will pivot when rotated.
Declaration
public Vector2 Anchor { get; set; }
Property Value
Type | Description |
---|---|
Vector2 |
Remarks
This value is a relative value where 0, 0 means the upper left of the sprite, and 1, 1 means the lower right.
Angle
Property to set or return the angle of rotation, in degrees.
Declaration
[JsonIgnore]
public float Angle { get; set; }
Property Value
Type | Description |
---|---|
float |
Bounds
Property to return the boundaries of the sprite.
Declaration
[JsonIgnore]
public RectangleF Bounds { get; }
Property Value
Type | Description |
---|---|
RectangleF |
Color
Property to set or return the color of the sprite.
Declaration
public GorgonColor Color { get; set; }
Property Value
Type | Description |
---|---|
GorgonColor |
Depth
Property to set or return the depth value for this sprite.
Declaration
[JsonIgnore]
public float Depth { get; set; }
Property Value
Type | Description |
---|---|
float |
HorizontalFlip
Property to set or return whether the sprite texture is flipped horizontally.
Declaration
public bool HorizontalFlip { get; set; }
Property Value
Type | Description |
---|---|
bool |
Remarks
This only flips the texture region mapped to the sprite. It does not affect the positioning or axis of the sprite.
Indices
Property to return whether this sprite contains any index data.
Declaration
[JsonIgnore]
public IReadOnlyList<int> Indices { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<int> |
IsUpdated
Property to return whether or not the sprite has had its position, size, texture information, or object space vertices updated since it was last drawn.
Declaration
[JsonIgnore]
public bool IsUpdated { get; }
Property Value
Type | Description |
---|---|
bool |
Position
Property to set or return the position of the sprite.
Declaration
[JsonIgnore]
public Vector2 Position { get; set; }
Property Value
Type | Description |
---|---|
Vector2 |
Scale
Property to set or return the scale factor to apply to the sprite.
Declaration
[JsonIgnore]
public Vector2 Scale { get; set; }
Property Value
Type | Description |
---|---|
Vector2 |
ScaledSize
Property to set or return the size of the renderable after scaling has been applied.
Declaration
[JsonIgnore]
public Size2F ScaledSize { get; set; }
Property Value
Type | Description |
---|---|
Size2F |
Remarks
This property will set or return the actual size of the renderable. This means that if a Scale has been set, then this property will return the size of the renderable with multiplied by the scale. When assigning a value, the scale be set on value derived from the current size of the renderable.
Size
Property to return the size of the sprite.
Declaration
[JsonIgnore]
public Size2F Size { get; }
Property Value
Type | Description |
---|---|
Size2F |
Texture
Property to set or return the texture to render.
Declaration
public GorgonTexture2DView Texture { get; set; }
Property Value
Type | Description |
---|---|
GorgonTexture2DView |
TextureArrayIndex
Property to set or return the texture array index for the sprite.
Declaration
public int TextureArrayIndex { get; set; }
Property Value
Type | Description |
---|---|
int |
TextureOffset
Property to set or return the offset to apply to a texture.
Declaration
public Vector2 TextureOffset { get; set; }
Property Value
Type | Description |
---|---|
Vector2 |
TextureSampler
Property to set or return the texture sampler to use when rendering.
Declaration
public GorgonSamplerState TextureSampler { get; set; }
Property Value
Type | Description |
---|---|
GorgonSamplerState |
TextureScale
Property to set or return the scale to apply to a texture.
Declaration
public Vector2 TextureScale { get; set; }
Property Value
Type | Description |
---|---|
Vector2 |
VerticalFlip
Property to set or return whether the sprite texture is flipped vertically.
Declaration
public bool VerticalFlip { get; set; }
Property Value
Type | Description |
---|---|
bool |
Remarks
This only flips the texture region mapped to the sprite. It does not affect the positioning or axis of the sprite.
Vertices
Property to return the list of vertices used by the poly sprite.
Declaration
[JsonIgnore]
public IReadOnlyList<GorgonPolySpriteVertex> Vertices { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<GorgonPolySpriteVertex> |
Methods
| Edit this page View SourceCreate(GorgonGraphics, IReadOnlyList<GorgonPolySpriteVertex>, IReadOnlyList<int>)
Function to build a GorgonPolySprite using predefined vertices and indices to define the polygonal sprite.
Declaration
public static GorgonPolySprite Create(GorgonGraphics graphics, IReadOnlyList<GorgonPolySpriteVertex> vertices, IReadOnlyList<int> indices)
Parameters
Type | Name | Description |
---|---|---|
GorgonGraphics | graphics | The graphics interface used to build up the vertex and index buffer for the polygonal sprite. |
IReadOnlyList<GorgonPolySpriteVertex> | vertices | The vertices for the polygonal sprite. |
IReadOnlyList<int> | indices | The indices for the polygonal sprite. |
Returns
Type | Description |
---|---|
GorgonPolySprite | A new GorgonPolySprite. |
Remarks
This method is used to build a GorgonPolySprite using already defined set of GorgonPolySpriteVertex vertices, and a set of indices. The vertices
must be triangulated (i.e. they must represent triangles) and not a hull. A minimum of 3 vertices and indices are required, otherwise an exception is thrown.
To define a polygon that doesn't need triangles, or indices, use the GorgonPolySpriteBuilder.
The vertices should be ordered in a clockwise orientation. This can be achieved by setting up the indices to point at each vertex in the desired order. For example:
// These define the corners of a rectangle.
Gorgon2PolySpriteVertex[] vertices = new Gorgon2PolySpriteVertex[4];
vertices[0] = new GorgonPolySpriteVertex(new Vector2(0, 0), ...);
vertices[1] = new GorgonPolySpriteVertex(new Vector2(30, 00), ...);
vertices[2] = new GorgonPolySpriteVertex(new Vector2(0, 30), ...);
vertices[3] = new GorgonPolySpriteVertex(new Vector2(30, 30), ...);
// To order the vertices so they'll render correctly:
int[] indices = new indices[6]; // We define 6 indices because the rect is made of 2 triangles, with 3 vertices each (we reuse some vertices for efficiency).
indices[0] = 0; // Use the first vertex, it is the upper left corner.
indices[1] = 1; // Use the second vertex, it is in the upper right corner.
indices[2] = 2; // Use the second vertex, it is in the lower left corner.
// The first triangle is defined, its vertices are ordered clockwise from the upper left corner giving a shape like:
// 0 1
// ------------
// | /
// | /
// | /
// | /
// | /
// | /
// * 2
indices[3] = 1;
indices[4] = 3;
indices[5] = 2;
// The second triangle is now defined, and its vertices are ordered clockwise from the upper right corner:
// 1
// ------------
// | /|
// | / |
// | / |
// | / |
// | / |
// | / |
// ------------
// 2 3
The resulting polygonal sprite IDisposable. Therefore, it is the user's responsibility to dispose of the object when they are done with it.
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
GorgonException | Thrown if the |
See Also
| Edit this page View SourceCreate(Gorgon2D, IReadOnlyList<GorgonPolySpriteVertex>, IReadOnlyList<int>)
Function to build a GorgonPolySprite using predefined vertices and indices to define the polygonal sprite.
Declaration
public static GorgonPolySprite Create(Gorgon2D renderer, IReadOnlyList<GorgonPolySpriteVertex> vertices, IReadOnlyList<int> indices)
Parameters
Type | Name | Description |
---|---|---|
Gorgon2D | renderer | The renderer interface used to build up the vertex and index buffer for the polygonal sprite. |
IReadOnlyList<GorgonPolySpriteVertex> | vertices | The vertices for the polygonal sprite. |
IReadOnlyList<int> | indices | The indices for the polygonal sprite. |
Returns
Type | Description |
---|---|
GorgonPolySprite | A new GorgonPolySprite. |
Remarks
This method is used to build a GorgonPolySprite using already defined set of GorgonPolySpriteVertex vertices, and a set of indices. The vertices
must be triangulated (i.e. they must represent triangles) and not a hull. A minimum of 3 vertices and indices are required, otherwise an exception is thrown.
To define a polygon that doesn't need triangles, or indices, use the GorgonPolySpriteBuilder.
The vertices should be ordered in a clockwise orientation. This can be achieved by setting up the indices to point at each vertex in the desired order. For example:
// These define the corners of a rectangle.
Gorgon2PolySpriteVertex[] vertices = new Gorgon2PolySpriteVertex[4];
vertices[0] = new GorgonPolySpriteVertex(new Vector2(0, 0), ...);
vertices[1] = new GorgonPolySpriteVertex(new Vector2(30, 00), ...);
vertices[2] = new GorgonPolySpriteVertex(new Vector2(0, 30), ...);
vertices[3] = new GorgonPolySpriteVertex(new Vector2(30, 30), ...);
// To order the vertices so they'll render correctly:
int[] indices = new indices[6]; // We define 6 indices because the rect is made of 2 triangles, with 3 vertices each (we reuse some vertices for efficiency).
indices[0] = 0; // Use the first vertex, it is the upper left corner.
indices[1] = 1; // Use the second vertex, it is in the upper right corner.
indices[2] = 2; // Use the second vertex, it is in the lower left corner.
// The first triangle is defined, its vertices are ordered clockwise from the upper left corner giving a shape like:
// 0 1
// ------------
// | /
// | /
// | /
// | /
// | /
// | /
// * 2
indices[3] = 1;
indices[4] = 3;
indices[5] = 2;
// The second triangle is now defined, and its vertices are ordered clockwise from the upper right corner:
// 1
// ------------
// | /|
// | / |
// | / |
// | / |
// | / |
// | / |
// ------------
// 2 3
The resulting polygonal sprite IDisposable. Therefore, it is the user's responsibility to dispose of the object when they are done with it.
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
GorgonException | Thrown if the |
See Also
| Edit this page View SourceDispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()