Class Sprite
Represents a 2D image. Such image is loaded from a content file (.wpk), which is generated from a main PNG or JPEG file format.
Inheritance
Implements
Inherited Members
Namespace: Evergine.Components.Graphics2D
Assembly: Evergine.Components.dll
Syntax
public class Sprite : Component, IDependencyObject
Constructors
Sprite()
Initializes a new instance of the Sprite class based on a content file.
Declaration
public Sprite()
Sprite(Texture)
Initializes a new instance of the Sprite class based on a texture. See Texture for more information.
Declaration
public Sprite(Texture texture)
Parameters
Type | Name | Description |
---|---|---|
Texture | texture | The texture. |
Exceptions
Type | Condition |
---|---|
ArgumentException | Texture can not be null. |
Sprite(Texture, SamplerState)
Initializes a new instance of the Sprite class.
Declaration
public Sprite(Texture texture, SamplerState sampler)
Parameters
Type | Name | Description |
---|---|---|
Texture | texture | The texture. |
SamplerState | sampler | The sampler. |
Fields
Transform2D
Required 2D transform. See Transform2D for more information.
Declaration
[BindComponent(true, true, BindComponentSource.Owner, null, true)]
public Transform2D Transform2D
Field Value
Type | Description |
---|---|
Transform2D |
sampler
The sprite sampler.
Declaration
protected SamplerState sampler
Field Value
Type | Description |
---|---|
SamplerState |
sliceIndex
Only when use textures (Texture2DArray).
Declaration
protected int sliceIndex
Field Value
Type | Description |
---|---|
int |
texture
The sprite texture.
Declaration
protected Texture texture
Field Value
Type | Description |
---|---|
Texture |
Properties
Sampler
Gets or sets the sampler. See SamplerState for more information.
Declaration
public SamplerState Sampler { get; set; }
Property Value
Type | Description |
---|---|
SamplerState |
SliceIndex
Gets or sets the array slice index of texture (Only Texture2DArray).
Declaration
public int SliceIndex { get; set; }
Property Value
Type | Description |
---|---|
int |
SourceRectangle
Gets or sets the Rectangle that represents this sprite in case it is part of a bigger image. Most of the cases this field will be null, which means the entire texture is used. On the other side, if a value is provided, will mean the rectangle (inside the original texture's rectangle) to be drawn.
Declaration
public Rectangle? SourceRectangle { get; set; }
Property Value
Type | Description |
---|---|
Rectangle? |
Texture
Gets or sets the texture. Such is the in-memory representation for the given asset. See Texture for more information.
Declaration
public Texture Texture { get; set; }
Property Value
Type | Description |
---|---|
Texture | The texture. |
TintColor
Gets or sets the tint color. Each pixel of the sprite will be multiplied by such color during the drawing. By default, it is white.
Declaration
public Color TintColor { get; set; }
Property Value
Type | Description |
---|---|
Color | The tint color. |
Methods
OnAttached()
Invoked when the object is attached to the system.
Declaration
protected override bool OnAttached()
Returns
Type | Description |
---|---|
bool | True if all is OK. |
Overrides
UpdateSourceRectangle()
The update source rectangle.
Declaration
protected void UpdateSourceRectangle()
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | Sprite has been disposed. |
Events
SamplerChanged
Event fired when this sprite sampler is changed
Declaration
public event EventHandler SamplerChanged
Event Type
Type | Description |
---|---|
EventHandler |
TextureChanged
Event fired when this sprite texture is changed
Declaration
public event EventHandler TextureChanged
Event Type
Type | Description |
---|---|
EventHandler |