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

Side by Side Diff: sky/examples/game/lib/node_with_size.dart

Issue 1190393004: Sprites correctly handles zPosition (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 unified diff | Download patch
« no previous file with comments | « sky/examples/game/lib/node.dart ('k') | sky/examples/game/lib/sprite_box.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 part of sprites; 1 part of sprites;
2 2
3 abstract class NodeWithSize extends Node { 3 abstract class NodeWithSize extends Node {
4 Size size; 4 Size size;
5 Point pivot; 5 Point pivot;
6 6
7 NodeWithSize() { 7 NodeWithSize() {
8 size = Size.zero; 8 size = Size.zero;
9 pivot = Point.origin; 9 pivot = Point.origin;
10 } 10 }
11 11
12 NodeWithSize.withSize(Size this.size, [Point this.pivot]) { 12 NodeWithSize.withSize(Size this.size, [Point this.pivot]) {
13 if (pivot == null) pivot = Point.origin; 13 if (pivot == null) pivot = Point.origin;
14 } 14 }
15 15
16 void applyTransformForPivot(PictureRecorder canvas) { 16 void applyTransformForPivot(PictureRecorder canvas) {
17 if (pivot.x != 0 || pivot.y != 0) { 17 if (pivot.x != 0 || pivot.y != 0) {
18 double pivotInPointsX = size.width * pivot.x; 18 double pivotInPointsX = size.width * pivot.x;
19 double pivotInPointsY = size.height * pivot.y; 19 double pivotInPointsY = size.height * pivot.y;
20 canvas.translate(-pivotInPointsX, -pivotInPointsY); 20 canvas.translate(-pivotInPointsX, -pivotInPointsY);
21 } 21 }
22 } 22 }
23 23
24 bool hitTest (Point nodePoint) { 24 bool isPointInside (Point nodePoint) {
25 25
26 double minX = -size.width * pivot.x; 26 double minX = -size.width * pivot.x;
27 double minY = -size.height * pivot.y; 27 double minY = -size.height * pivot.y;
28 double maxX = minX + size.width; 28 double maxX = minX + size.width;
29 double maxY = minY + size.height; 29 double maxY = minY + size.height;
30 return (nodePoint.x >= minX && nodePoint.x < maxX && 30 return (nodePoint.x >= minX && nodePoint.x < maxX &&
31 nodePoint.y >= minY && nodePoint.y < maxY); 31 nodePoint.y >= minY && nodePoint.y < maxY);
32 } 32 }
33 } 33 }
OLDNEW
« no previous file with comments | « sky/examples/game/lib/node.dart ('k') | sky/examples/game/lib/sprite_box.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698