Skip to main content

Sprite

Namespace: MonineEngine.Graphics

Represents a drawable 2D texture region with additional properties for rendering such as position, scale, rotation, and colour.

public class Sprite

Inheritance ObjectSprite
Attributes NullableContextAttribute, NullableAttribute

Properties

Region

Gets or sets the source texture region represented by this sprite.

public TextureRegion Region { get; set; }

Property Value

TextureRegion

Texture

The texture of the sprite, defined by the Region of the sprite.

public Texture2D Texture { get; set; }

Property Value

Texture2D

Color

The color mask to apply when rendering this sprite. Acts as a tint.

public Color Color { get; set; }

Property Value

Color

Remarks:

Default value is Colour.White

Rotation

The rotation, in radians, to apply when rendering this sprite.

public float Rotation { get; set; }

Property Value

Single

Remarks:

Default value is 0.0f

Scale

The scale factor to apply to the texture when rendering the sprite.

public Vector2 Scale { get; set; }

Property Value

Vector2

Remarks:

Default value is Vector2.One

Origin

The origin point of the texture, relative to the top-left corner, of this sprite.

public Vector2 Origin { get; set; }

Property Value

Vector2

Remarks:

Default value is Vector2.Zero.

Effects

Gets or Sets the sprite effects to apply when rendering this sprite.

public SpriteEffects Effects { get; set; }

Property Value

SpriteEffects

Remarks:

Default value is SpriteEffects.None

LayerDepth

Gets or Sets the layer depth to apply when rendering this sprite.

public float LayerDepth { get; set; }

Property Value

Single

Remarks:

Default value is 0.0f

Width

Gets the width, in pixels, of this sprite.

public float Width { get; }

Property Value

Single

Remarks:

Width is calculated by multiplying the width of the source texture region by the x-axis scale factor.

Height

Gets the height, in pixels, of this sprite.

public float Height { get; }

Property Value

Single

Remarks:

Height is calculated by multiplying the height of the source texture region by the y-axis scale factor.

Constructors

Sprite()

Creates a new Sprite loaded with the null texture of Monine Engine.

public Sprite()

Sprite(Texture2D, Rectangle)

Creates a new Sprite using the specified texture and bounds.

public Sprite(Texture2D texture, Rectangle region)

Parameters

texture Texture2D
The texture for this Sprite.

region Rectangle
The bounds of the region within the texture for the Sprite to render.

Sprite(Texture2D)

Creates a new Sprite using the specified texture.

public Sprite(Texture2D texture)

Parameters

texture Texture2D
The texture for this Sprite.

Sprite(TextureRegion)

Creates a new Sprite using the specified texture region.

public Sprite(TextureRegion region)

Parameters

region TextureRegion
The region to use as the source texture region for this Sprite.

Methods

CenterOrigin()

Sets the origin of this Sprite to the center of the current TextureRegion.

public void CenterOrigin()

Draw(IRendererService, Vector2, Vector2, Single, Color)

Submit this sprite for drawing to the current batch.

public void Draw(IRendererService service, Vector2 position, Vector2 scale, float rotation, Color colour)

Parameters

service IRendererService
The RendererService instance for drawing the sprite.

position Vector2
The position to render this sprite at.

scale Vector2
The scale to render this sprite at. Acts as a modifier to the sprite scale.

rotation Single
The rotation to render this sprite at. Acts as a modifier to the sprite rotation.

colour Color
The colour to render this sprite with. Acts as a modifier to the sprite colour.