CanvasSpriteBatchDrawFromSpriteSheet Method (CanvasBitmap, Vector2, Rect, Vector4, Vector2, Single, Vector2, CanvasSpriteFlip) |
Namespace: Microsoft.Graphics.Canvas
public void DrawFromSpriteSheet( CanvasBitmap bitmap, Vector2 offset, Rect sourceRect, Vector4 tint, Vector2 origin, float rotation, Vector2 scale, CanvasSpriteFlip flip )
This API is only available when running on Windows 10 build 10586 (released November 2015) or greater.
The origin parameter is specified relative to the source bitmap. The image is then drawn such that the origin is in the position specified by the offset. The rotation and scale are performed around the origin.
The tint parameter is specified in non-premultiplied format.
The value of the tint parameter is a Vector4 that specifies the red, green, blue and alpha amounts to scale the bitmap's color by. The default value is Vector4.One, which would result in scaling all four color channels by 1, keeping everything the same. A value of Vector4(2, 1, 1, 1) would tint the sprite red by doubling the red amount of each source color. A value of Vector4(1, 1, 1, 0.5f) would draw the sprite at half opacity.
You can tint with a Windows.UI.Color type by using:
void DrawSomeSprites(CanvasDrawingSession ds) { using (var spriteBatch = ds.CreateSpriteBatch()) { spriteBatch.Draw(image, destRect, new Vector4(Color.R, Color.G, Color.B, Color.A) / 255.0f); } }