diff --git a/projects/flixel-desktop-habit-puzzle-game/source/jigsawx/JigsawPiece.hx b/projects/flixel-desktop-habit-puzzle-game/source/jigsawx/JigsawPiece.hx index 3e674132..d66d3eae 100644 --- a/projects/flixel-desktop-habit-puzzle-game/source/jigsawx/JigsawPiece.hx +++ b/projects/flixel-desktop-habit-puzzle-game/source/jigsawx/JigsawPiece.hx @@ -71,16 +71,28 @@ class JigsawPiece{ if( sideData.west != null ) createHoriSide( lb, lt, bubbleSize, sideData.west, WEST ); points.push( lt ); + var minX = Math.POSITIVE_INFINITY; + var minY = Math.POSITIVE_INFINITY; var maxX = 0.0; var maxY = 0.0; for (point in points) { + if (point.x < minX) + minX = point.x; + if (point.y < minY) + minY = point.y; if (point.x > maxX) maxX = point.x; if (point.y > maxY) maxY = point.y; } wh = new Vec2(maxX, maxY); + // Crop the points so we don't make a bigger source rectangle than needed: + xy.add(minX, minY); + for (point in points.concat([wh])) { + point.subtract(minX, minY); + } } + public function getPoints(): Array { return points; } diff --git a/projects/flixel-desktop-habit-puzzle-game/source/jigsawx/math/Vec2.hx b/projects/flixel-desktop-habit-puzzle-game/source/jigsawx/math/Vec2.hx index 79036e79..04323370 100644 --- a/projects/flixel-desktop-habit-puzzle-game/source/jigsawx/math/Vec2.hx +++ b/projects/flixel-desktop-habit-puzzle-game/source/jigsawx/math/Vec2.hx @@ -9,6 +9,14 @@ class Vec2{ public function copy() { return new Vec2(x, y); } + public function add(dx:Float, dy:Float) { + x += dx; + y += dy; + } + public function subtract(dx:Float, dy:Float) { + x -= dx; + y -= dy; + } public function toString() { return '(${x}, ${y})'; }