flutter/examples/game/lib/node_with_size.dart
Viktor Lidholt 627aeff31a Optimizes sprite transformations for box to node
Enabling/disabling of handling multiple pointers
Adds basic touch handling

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/1179413009.
2015-06-18 15:29:26 -07:00

34 lines
857 B
Dart

part of sprites;
abstract class NodeWithSize extends Node {
Size size;
Point pivot;
NodeWithSize() {
size = Size.zero;
pivot = Point.origin;
}
NodeWithSize.withSize(Size this.size, [Point this.pivot]) {
if (pivot == null) pivot = Point.origin;
}
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);
}
}