mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Merge pull request #441 from vlidholt/master
Optimizes drawing performance in sprites
This commit is contained in:
commit
3e6ace0420
@ -29,7 +29,9 @@ class Sprite extends NodeWithSize {
|
||||
/// mySprite.transferMode = TransferMode.plusMode;
|
||||
TransferMode transferMode;
|
||||
|
||||
Paint _cachedPaint = new Paint();
|
||||
Paint _cachedPaint = new Paint()
|
||||
..setFilterQuality(FilterQuality.low)
|
||||
..isAntiAlias = false;
|
||||
|
||||
/// Creates a new sprite from the provided [texture].
|
||||
///
|
||||
|
||||
@ -74,17 +74,18 @@ class Texture {
|
||||
}
|
||||
|
||||
void drawTexture(PaintingCanvas canvas, Point position, Paint paint) {
|
||||
|
||||
// Account for position
|
||||
// Get drawing position
|
||||
double x = position.x;
|
||||
double y = position.y;
|
||||
bool translate = (x != 0 || y != 0);
|
||||
if (translate) {
|
||||
canvas.translate(x, 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);
|
||||
@ -97,14 +98,15 @@ class Texture {
|
||||
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
|
||||
canvas.drawImageRect(image, frame, spriteSourceSize, paint);
|
||||
}
|
||||
|
||||
// Translate back
|
||||
if (translate) {
|
||||
canvas.translate(-x, -y);
|
||||
Rect dstRect = new Rect.fromLTWH(x + spriteSourceSize.left, y + spriteSourceSize.top, spriteSourceSize.width, spriteSourceSize.height);
|
||||
canvas.drawImageRect(image, frame, dstRect, paint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user