add invert X or Y axis to position component

This commit is contained in:
kurtome
2019-10-06 17:17:48 -04:00
committed by Erick (CptBlackPixel)
parent 1dabf46712
commit 627e12bba2

View File

@ -64,6 +64,8 @@ abstract class PositionComponent extends Component {
double x = 0.0, y = 0.0, angle = 0.0; double x = 0.0, y = 0.0, angle = 0.0;
double width = 0.0, height = 0.0; double width = 0.0, height = 0.0;
Anchor anchor = Anchor.topLeft; Anchor anchor = Anchor.topLeft;
bool renderFlipX = false;
bool renderFlipY = false;
bool debugMode = false; bool debugMode = false;
@ -128,6 +130,11 @@ abstract class PositionComponent extends Component {
final double dy = -anchor.relativePosition.dy * height; final double dy = -anchor.relativePosition.dy * height;
canvas.translate(dx, dy); canvas.translate(dx, dy);
// Handle inverted rendering by moving center and flipping.
canvas.translate(width / 2, height / 2);
canvas.scale(renderFlipX ? -1.0 : 1.0, renderFlipY ? -1.0 : 1.0);
canvas.translate(-width / 2, -height / 2);
if (debugMode) { if (debugMode) {
renderDebugMode(canvas); renderDebugMode(canvas);
} }