flutter/examples/game/lib/node_with_size.dart
Viktor Lidholt 43d97f6903 Correctly handle touches together with zPosition
Renames hitTest to isPointInside

Refactor sorting of children in nodes

Fixes zPosition in sprites and hides internal methods

Adds scaleX / scaleY properties

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/1190393004.
2015-06-19 11:15:58 -07:00

34 lines
863 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 isPointInside (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);
}
}