Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Unified Diff: sky/examples/game/lib/sprite.dart

Issue 1212073002: Improved documentation for SkyGames and support for rotated textures (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sky/examples/game/lib/spritesheet.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/examples/game/lib/sprite.dart
diff --git a/sky/examples/game/lib/sprite.dart b/sky/examples/game/lib/sprite.dart
index 22ddbee237558f96985707f8af4ca995c3b16160..6202e20e30b4abced89a1f19f36f9fe7311b3145 100644
--- a/sky/examples/game/lib/sprite.dart
+++ b/sky/examples/game/lib/sprite.dart
@@ -103,11 +103,26 @@ class Sprite extends NodeWithSize {
}
// Do actual drawing of the sprite
- canvas.drawImageRect(texture.image, texture.frame, texture.spriteSourceSize, paint);
+ if (texture.rotated) {
+ // Calculate the rotated frame and spriteSourceSize
+ Size originalFrameSize = texture.frame.size;
+ Rect rotatedFrame = new Rect.fromPointAndSize(texture.frame.upperLeft, new Size(originalFrameSize.height, originalFrameSize.width));
+ Point rotatedSpriteSourcePoint = new Point(
+ -texture.spriteSourceSize.top - (texture.spriteSourceSize.bottom - texture.spriteSourceSize.top),
+ texture.spriteSourceSize.left);
+ Rect rotatedSpriteSourceSize = new Rect.fromPointAndSize(rotatedSpriteSourcePoint, new Size(originalFrameSize.height, originalFrameSize.width));
+
+ // Draw the rotated sprite
+ canvas.rotate(-Math.PI/2.0);
+ canvas.drawImageRect(texture.image, rotatedFrame, rotatedSpriteSourceSize, paint);
+ } else {
+ // Draw the sprite
+ canvas.drawImageRect(texture.image, texture.frame, texture.spriteSourceSize, paint);
+ }
} else {
// Paint a red square for missing texture
canvas.drawRect(new Rect.fromLTRB(0.0, 0.0, size.width, size.height),
- new Paint()..color = const Color.fromARGB(255, 255, 0, 0));
+ new Paint()..color = const Color.fromARGB(255, 255, 0, 0));
}
canvas.restore();
}
« no previous file with comments | « no previous file | sky/examples/game/lib/spritesheet.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698