public static ConvertToWinRectangle ( Math rectangle ) : |
||
rectangle | Math | The Rectangle. |
Результат |
/// <summary> /// Draws a Texture. /// </summary> /// <param name="spriteSheet">The SpriteSheet.</param> /// <param name="position">The Position.</param> /// <param name="color">The Color.</param> /// <param name="opacity">The Opacity.</param> public void DrawTexture(SpriteSheet spriteSheet, Vector2 position, Color color, float opacity = 1) { var dxTexture = spriteSheet.Texture2D as DirectXTexture; if (dxTexture == null) { throw new ArgumentException("DirectX9 expects a DirectXTexture as resource."); } _sprite.Draw(dxTexture.GetTexture(), DirectXHelper.ConvertToWinRectangle(spriteSheet.Rectangle), null, DirectXHelper.ConvertVector3(position), DirectXHelper.ConvertColor(color)); }
/// <summary> /// Draws a string. /// </summary> /// <param name="text">The Text.</param> /// <param name="font">The Font.</param> /// <param name="rectangle">The Rectangle.</param> /// <param name="color">The Color.</param> public void DrawString(string text, Font font, Rectangle rectangle, Color color) { var dxFont = font.Instance as DirectXFont; if (dxFont == null) { throw new ArgumentException("DirectX9 expects a DirectXFont as resource."); } dxFont.GetFont() .DrawString(_sprite, text, DirectXHelper.ConvertToWinRectangle(rectangle), DrawTextFormat.WordBreak, DirectXHelper.ConvertColor(color)); }
/// <summary> /// Draws a Texture. /// </summary> /// <param name="spriteSheet">The SpriteSheet.</param> /// <param name="rectangle">The Rectangle.</param> /// <param name="color">The Color.</param> /// <param name="opacity">The Opacity.</param> public void DrawTexture(SpriteSheet spriteSheet, Rectangle rectangle, Color color, float opacity = 1) { var dxTexture = spriteSheet.Texture2D as DirectXTexture; if (dxTexture == null) { throw new ArgumentException("DirectX9 expects a DirectXTexture as resource."); } //calc percentages for scaling float scaleX = rectangle.Width / spriteSheet.Rectangle.Width; float scaleY = rectangle.Height / spriteSheet.Rectangle.Height; _sprite.Transform = Matrix.Scaling(scaleX, scaleY, 1f); _sprite.Draw(dxTexture.GetTexture(), DirectXHelper.ConvertToWinRectangle(spriteSheet.Rectangle), null, DirectXHelper.ConvertVector3(new Vector2(rectangle.X / scaleX, rectangle.Y / scaleY)), DirectXHelper.ConvertColor(color)); _sprite.Transform = Matrix.Identity; }