From b7e54c24a04be9341dd37ed94c29d7836bfb6e0a Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Thu, 16 Dec 2021 14:58:51 -0700 Subject: [PATCH] Allow relative sizing when drawing sprite on sprite --- .../hollywoo-flixel/src/hollywoo_flixel/SpriteTools.hx | 2 ++ .../src/hollywoo_flixel/SpriteTools.kiss | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/projects/hollywoo-flixel/src/hollywoo_flixel/SpriteTools.hx b/projects/hollywoo-flixel/src/hollywoo_flixel/SpriteTools.hx index e5443484..3587c0b6 100644 --- a/projects/hollywoo-flixel/src/hollywoo_flixel/SpriteTools.hx +++ b/projects/hollywoo-flixel/src/hollywoo_flixel/SpriteTools.hx @@ -18,6 +18,8 @@ typedef RelativePosition = { y:RelativeCoordinate, ?anchorX:RelativeCoordinate, // default Percent(0.5) ?anchorY:RelativeCoordinate, // default Percent(0.5) + ?sizeX:RelativeCoordinate, + ?sizeY:RelativeCoordinate, }; @:build(kiss.Kiss.build()) diff --git a/projects/hollywoo-flixel/src/hollywoo_flixel/SpriteTools.kiss b/projects/hollywoo-flixel/src/hollywoo_flixel/SpriteTools.kiss index 8bb0c364..5c77fe76 100644 --- a/projects/hollywoo-flixel/src/hollywoo_flixel/SpriteTools.kiss +++ b/projects/hollywoo-flixel/src/hollywoo_flixel/SpriteTools.kiss @@ -21,9 +21,19 @@ p) (otherwise (throw "$coord is out of range $range"))))) +(function :Void scaleStampOn [:FlxSprite stamp :FlxSprite canvas :RelativePosition pos] + (let [&mut x 0 &mut y 0] + (when pos.sizeX + (set x (coordIn pos.sizeX canvas.frameWidth))) + (when pos.sizeY + (set y (coordIn pos.sizeY canvas.frameHeight))) + (stamp.setGraphicSize x y) + (stamp.updateHitbox))) + // TODO allow specifying size relative to canvas (function :Void drawOnSprite [:FlxSprite stamp :FlxSprite canvas :RelativePosition pos] (let [[x y] (positionOn stamp canvas pos)] + (scaleStampOn stamp canvas pos) (canvas.stamp stamp x y))) // TODO allow specifying size relative to canvas