Allow relative sizing when drawing sprite on sprite

This commit is contained in:
2021-12-16 14:58:51 -07:00
parent 8056f1f871
commit d0a8a78713
2 changed files with 12 additions and 0 deletions

View File

@@ -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())

View File

@@ -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