I need the rendered dimensions of a sprite, I'm calling Draw in the class below:
public class Ship
{
public Ship(Texture2D texture)
{
Width = texture.Width;
Height = texture.Height;
Texture = texture;
}
public int Width { get; set; }
public int Height { get; set; }
public float Scale { get; set; }
public Vector2 Position { get; set; }
public Texture2D Texture { get; }
public Rectangle Rectangle => new Rectangle((int)Position.X, (int) Position.Y, Width, Height);
public void Draw(SpriteBatch batch)
{
var origin = new Vector2(Texture.Width / 2, Texture.Height / 2);
var scale = new Vector2(Scale, Scale);
var rotation = GetRotationInRadians();
batch.Draw(Texture, Position, null, Color.White,
rotation,
origin,
scale,
SpriteEffects.None, 0f);
}
}
The problem is Width and Height are based off the source (see the constructor) Texture size, so after drawing they are not actual dimensions. Is there away to determine the scaled sprite size?
Side note: I'm using these dimension to detect if an sprite was clicked on by the mouse. Maybe there is a better way to detect clicks?