flutter/examples/game/lib/node_with_size.dart
Viktor Lidholt 6c7a619f99 Updates game for new AppView API
Deletes old test game

Demo game is now playable

Updates demo game with steering and changes in sprites

Fixes smaller bugs in sprites

Refactor class names in game demo

Strips Box2D from game

Fixes ordering in game node

Adds frameRate property to SpriteBox and improves update methods.

Fixes node to box transformations for hit tests

Fixes minor code issues

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/1179333002.
2015-06-15 09:11:16 -07:00

32 lines
807 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]);
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);
}
}