fix puzzle piece optimization
This commit is contained in:
@@ -33,7 +33,7 @@ import jigsawx.math.Vec2;
|
|||||||
class HabitState extends FlxState {
|
class HabitState extends FlxState {
|
||||||
public function drawPieceShape( surface: FlxSprite, jig: JigsawPiece, c: FlxColor )
|
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]);
|
points.push(points[0]);
|
||||||
FlxSpriteUtil.drawPolygon(
|
FlxSpriteUtil.drawPolygon(
|
||||||
surface,
|
surface,
|
||||||
|
@@ -78,26 +78,24 @@
|
|||||||
(doFor y (range PUZZLE_HEIGHT)
|
(doFor y (range PUZZLE_HEIGHT)
|
||||||
(doFor x (range PUZZLE_WIDTH)
|
(doFor x (range PUZZLE_WIDTH)
|
||||||
(startingPoints.push (new FlxPoint (+ rewardSprite.x (* x PIECE_WIDTH)) (+ rewardSprite.y (* y PIECE_HEIGHT))))))
|
(startingPoints.push (new FlxPoint (+ rewardSprite.x (* x PIECE_WIDTH)) (+ rewardSprite.y (* y PIECE_HEIGHT))))))
|
||||||
//(r.shuffle startingPoints)
|
(r.shuffle startingPoints)
|
||||||
(set jigsaw j)
|
(set jigsaw j)
|
||||||
(doFor i (range (- p currentRewardFile.startingPoints))
|
(doFor i (range (min TOTAL_PIECES (- p currentRewardFile.startingPoints)))
|
||||||
(let [jig (nth jigsaw.jigs i)
|
(let [jig (nth jigsaw.jigs i)
|
||||||
pos (nth startingPoints i)
|
pos (nth startingPoints i)
|
||||||
s (new FlxExtendedSprite pos.x pos.y)
|
s (new FlxExtendedSprite pos.x pos.y)
|
||||||
source (new FlxSprite)
|
source (new FlxSprite)
|
||||||
mask (new FlxSprite)
|
mask (new FlxSprite)
|
||||||
sourceRect (new Rectangle jig.xy.x jig.xy.y jig.wh.x jig.wh.y)]
|
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)
|
(set s.draggable true)
|
||||||
(s.enableMouseDrag false true)
|
(s.enableMouseDrag false true)
|
||||||
|
|
||||||
(source.makeGraphic (Std.int sourceRect.width) (Std.int sourceRect.height) FlxColor.TRANSPARENT true)
|
(source.makeGraphic (Std.int sourceRect.width) (Std.int sourceRect.height) FlxColor.TRANSPARENT true)
|
||||||
(source.pixels.copyPixels rewardSprite.pixels sourceRect (new Point 0 0))
|
(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)
|
(drawPieceShape mask jig FlxColor.BLACK)
|
||||||
(FlxSpriteUtil.alphaMask s rewardSprite.pixels mask.pixels)
|
(FlxSpriteUtil.alphaMask s source.pixels mask.pixels)
|
||||||
|
|
||||||
(set s.cameras [pieceCamera])
|
(set s.cameras [pieceCamera])
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user