1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace MonoGameLibrary.Graphics;
///<summary>
/// Represents a rectangular region within a texture
///</summary>
public class TextureRegion
{
/// <summary>
/// Gets or Sets the source texture this texture region is part of
/// </summary>
public Texture2D Texture { get; set; }
/// <summary>
/// Gets or Sets the source rectangle boundary of this texture region within the source texture
/// </summary>
public Rectangle SourceRectangle { get; set; }
/// <summary>
/// Gets the width, in pixels, of this texture region
/// </summary>
public int Width => SourceRectangle.Width;
/// <summary>
/// Gets the height, in pixels, of this texture region/
/// </summary>
public int Height => SourceRectangle.Height;
/// <summary>
/// Creates a new texture region.
/// </summary>
public TextureRegion() { }
public TextureRegion(Texture2D texture, int x, int y, int width, int height)
{
Texture = texture;
SourceRectangle = new Rectangle(x, y, width, height);
}
public void Draw(SpriteBatch spriteBatch, Vector2 position, Color color)
{
Draw(spriteBatch, position, color, 0.0f, Vector2.Zero, Vector2.One, SpriteEffects.None, 0.0f);
}
public void Draw(SpriteBatch spriteBatch, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth)
{
Draw(
spriteBatch,
position,
color,
rotation,
origin,
new Vector2(scale, scale),
effects,
layerDepth
);
}
public void Draw(SpriteBatch spriteBatch, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
{
spriteBatch.Draw(
Texture,
position,
SourceRectangle,
color,
rotation,
origin,
scale,
effects,
layerDepth
);
}
}
|