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

Unified Diff: sky/sdk/example/game/lib/texture.dart

Issue 1216573009: Adds particle systems to sprites (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
Index: sky/sdk/example/game/lib/texture.dart
diff --git a/sky/sdk/example/game/lib/texture.dart b/sky/sdk/example/game/lib/texture.dart
index 82c822a62cabc93b786fe3ffcb5deb7941f1f290..1c22e4ca88ea0400dddc0d24de67c97f2a09007a 100644
--- a/sky/sdk/example/game/lib/texture.dart
+++ b/sky/sdk/example/game/lib/texture.dart
@@ -65,9 +65,46 @@ class Texture {
this.spriteSourceSize, this.pivot) {
}
-// Texture textureFromRect(Rect rect, [String name = null]) {
-// assert(rect != null);
-// Rect frame = new Rect.fromLTRB();
-// return new Texture._fromSpriteFrame(image, name, rect.size, false, false, );
-// }
+ Texture textureFromRect(Rect rect, [String name = null]) {
+ assert(rect != null);
+ assert(!rotated);
+ Rect srcFrame = new Rect.fromLTWH(rect.left + frame.left, rect.top + frame.top, rect.size.width, rect.size.height);
+ Rect dstFrame = new Rect.fromLTWH(0.0, 0.0, rect.size.width, rect.size.height);
+ return new Texture._fromSpriteFrame(image, name, rect.size, false, false, srcFrame, dstFrame, new Point(0.5, 0.5));
+ }
+
+ void drawTexture(PaintingCanvas canvas, Point position, Paint paint) {
+
+ // Account for 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) {
+ // Calculate the rotated frame and spriteSourceSize
+ Size originalFrameSize = frame.size;
+ Rect rotatedFrame = new Rect.fromPointAndSize(frame.upperLeft, new Size(originalFrameSize.height, originalFrameSize.width));
+ Point rotatedSpriteSourcePoint = new Point(
+ -spriteSourceSize.top - (spriteSourceSize.bottom - spriteSourceSize.top),
+ 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(image, rotatedFrame, rotatedSpriteSourceSize, paint);
+ canvas.rotate(Math.PI/2.0);
+ } else {
+ // Draw the sprite
+ canvas.drawImageRect(image, frame, spriteSourceSize, paint);
+ }
+
+ // Translate back
+ if (translate) {
+ canvas.translate(-x, -y);
+ }
+ }
}
« sky/sdk/example/game/lib/game_demo_world.dart ('K') | « sky/sdk/example/game/lib/sprites.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698