Draws the texture to a Canvas at a specified position
and with the
specified paint
.
Source
void drawTexture(Canvas canvas, Point position, Paint paint) { // Get drawing position double x = position.x; double y = position.y; // Draw the texture if (rotated) { // Account for position bool translate = (x != 0 || y != 0); if (translate) { canvas.translate(x, y); } // Calculate the rotated frame and spriteSourceSize Size originalFrameSize = frame.size; Rect rotatedFrame = frame.topLeft & new Size(originalFrameSize.height, originalFrameSize.width); Point rotatedSpriteSourcePoint = new Point( -spriteSourceSize.top - (spriteSourceSize.bottom - spriteSourceSize.top), spriteSourceSize.left); Rect rotatedSpriteSourceSize = rotatedSpriteSourcePoint & new Size(originalFrameSize.height, originalFrameSize.width); // Draw the rotated sprite canvas.rotate(-math.PI/2.0); canvas.drawImageRect(image, rotatedFrame, rotatedSpriteSourceSize, paint); canvas.rotate(math.PI/2.0); // Translate back if (translate) { canvas.translate(-x, -y); } } else { // Draw the sprite Rect dstRect = new Rect.fromLTWH(x + spriteSourceSize.left, y + spriteSourceSize.top, spriteSourceSize.width, spriteSourceSize.height); canvas.drawImageRect(image, frame, dstRect, paint); } }