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

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

Issue 1180703002: Fixes matrix transformations in 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/examples/game/lib/node_with_size.dart
diff --git a/sky/examples/game/lib/node_with_size.dart b/sky/examples/game/lib/node_with_size.dart
new file mode 100644
index 0000000000000000000000000000000000000000..1e7c65729c90c1f9060a30690531a67c2a52f040
--- /dev/null
+++ b/sky/examples/game/lib/node_with_size.dart
@@ -0,0 +1,31 @@
+part of sprites;
+
+abstract class NodeWithSize extends Node {
+ Size size;
+ Point pivot;
+
+ NodeWithSize() {
+ size = new Size(0.0, 0.0);
+ pivot = new Point(0.0, 0.0);
abarth-chromium 2015/06/11 00:20:20 Size.zero Point.origin
+ }
+
+ NodeWithSize.withSize(Size size, [Point pivot]);
+
+ void applyTransformForPivot(PictureRecorder canvas) {
+ if (pivot.x != 0 || pivot.y != 0) {
+ double pivotInPointsX = size.width * pivot.x;
+ double pivotInPointsY = size.height * pivot.y;
+ canvas.translate(-pivotInPointsX, -pivotInPointsY);
+ }
+ }
+
+ bool hitTest (Point nodePoint) {
+
+ double minX = -size.width * pivot.x;
+ double minY = -size.height * pivot.y;
+ double maxX = minX + size.width;
+ double maxY = minY + size.height;
+ return (nodePoint.x >= minX && nodePoint.x < maxX &&
+ nodePoint.y >= minY && nodePoint.y < maxY);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698