Allow relative sizing when drawing sprite on sprite
This commit is contained in:
@@ -18,6 +18,8 @@ typedef RelativePosition = {
|
|||||||
y:RelativeCoordinate,
|
y:RelativeCoordinate,
|
||||||
?anchorX:RelativeCoordinate, // default Percent(0.5)
|
?anchorX:RelativeCoordinate, // default Percent(0.5)
|
||||||
?anchorY:RelativeCoordinate, // default Percent(0.5)
|
?anchorY:RelativeCoordinate, // default Percent(0.5)
|
||||||
|
?sizeX:RelativeCoordinate,
|
||||||
|
?sizeY:RelativeCoordinate,
|
||||||
};
|
};
|
||||||
|
|
||||||
@:build(kiss.Kiss.build())
|
@:build(kiss.Kiss.build())
|
||||||
|
@@ -21,9 +21,19 @@
|
|||||||
p)
|
p)
|
||||||
(otherwise (throw "$coord is out of range $range")))))
|
(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
|
// TODO allow specifying size relative to canvas
|
||||||
(function :Void drawOnSprite [:FlxSprite stamp :FlxSprite canvas :RelativePosition pos]
|
(function :Void drawOnSprite [:FlxSprite stamp :FlxSprite canvas :RelativePosition pos]
|
||||||
(let [[x y] (positionOn stamp canvas pos)]
|
(let [[x y] (positionOn stamp canvas pos)]
|
||||||
|
(scaleStampOn stamp canvas pos)
|
||||||
(canvas.stamp stamp x y)))
|
(canvas.stamp stamp x y)))
|
||||||
|
|
||||||
// TODO allow specifying size relative to canvas
|
// TODO allow specifying size relative to canvas
|
||||||
|
Reference in New Issue
Block a user