fix puzzle piece optimization

This commit is contained in:
2022-07-09 01:15:29 +00:00
parent 1d7fe13705
commit 5cd71fa8b8
2 changed files with 5 additions and 7 deletions

View File

@@ -33,7 +33,7 @@ import jigsawx.math.Vec2;
class HabitState extends FlxState {
public function drawPieceShape( surface: FlxSprite, jig: JigsawPiece, c: FlxColor )
{
var points = [for (point in jig.getPoints()) new FlxPoint(jig.xy.x + point.x, jig.xy.y + point.y)];
var points = [for (point in jig.getPoints()) new FlxPoint(point.x, point.y)];
points.push(points[0]);
FlxSpriteUtil.drawPolygon(
surface,

View File

@@ -78,26 +78,24 @@
(doFor y (range PUZZLE_HEIGHT)
(doFor x (range PUZZLE_WIDTH)
(startingPoints.push (new FlxPoint (+ rewardSprite.x (* x PIECE_WIDTH)) (+ rewardSprite.y (* y PIECE_HEIGHT))))))
//(r.shuffle startingPoints)
(r.shuffle startingPoints)
(set jigsaw j)
(doFor i (range (- p currentRewardFile.startingPoints))
(doFor i (range (min TOTAL_PIECES (- p currentRewardFile.startingPoints)))
(let [jig (nth jigsaw.jigs i)
pos (nth startingPoints i)
s (new FlxExtendedSprite pos.x pos.y)
source (new FlxSprite)
mask (new FlxSprite)
sourceRect (new Rectangle jig.xy.x jig.xy.y jig.wh.x jig.wh.y)]
(-= pos.x jig.xy.x)
(-= pos.y jig.xy.y)
(set s.draggable true)
(s.enableMouseDrag false true)
(source.makeGraphic (Std.int sourceRect.width) (Std.int sourceRect.height) FlxColor.TRANSPARENT true)
(source.pixels.copyPixels rewardSprite.pixels sourceRect (new Point 0 0))
(mask.makeGraphic graphicWidth graphicHeight FlxColor.TRANSPARENT true)
(mask.makeGraphic (Std.int sourceRect.width) (Std.int sourceRect.height) FlxColor.TRANSPARENT true)
(drawPieceShape mask jig FlxColor.BLACK)
(FlxSpriteUtil.alphaMask s rewardSprite.pixels mask.pixels)
(FlxSpriteUtil.alphaMask s source.pixels mask.pixels)
(set s.cameras [pieceCamera])