writeOnSprite allow multiline with anchors
This commit is contained in:
@@ -20,6 +20,8 @@ typedef RelativePosition = {
|
||||
?anchorY:RelativeCoordinate, // default Percent(0.5)
|
||||
?sizeX:RelativeCoordinate,
|
||||
?sizeY:RelativeCoordinate,
|
||||
?offsetX:Int,
|
||||
?offsetY:Int
|
||||
};
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
|
@@ -8,7 +8,8 @@
|
||||
(-= y (coordIn pos.anchorY (/ stamp.height stamp.scale.y)))
|
||||
[x y]))
|
||||
|
||||
(function :Int coordIn [:RelativeCoordinate coord :Int range]
|
||||
(function :Int coordIn [:RelativeCoordinate coord :Int range &opt :Int offset]
|
||||
(+ (or offset 0)
|
||||
(Math.round
|
||||
(case coord
|
||||
((when (and (>= p -1) (< p 0)) (Percent p))
|
||||
@@ -19,7 +20,7 @@
|
||||
(* range p))
|
||||
((when (<= p range) (Pixels 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]
|
||||
@@ -37,7 +38,12 @@
|
||||
|
||||
// TODO allow specifying size relative to canvas
|
||||
(function :Void writeOnSprite [:String text :Int size :FlxSprite canvas :RelativePosition pos &opt :FlxColor color]
|
||||
(let [lines (text.split "\n")
|
||||
&mut offsetY (/ (* size lines.length) -2)]
|
||||
(doFor text lines
|
||||
(set pos.offsetY offsetY)
|
||||
(+= offsetY size)
|
||||
(let [text (new FlxText 0 0 0 text size)]
|
||||
(when color
|
||||
(set text.color color))
|
||||
(drawOnSprite text canvas pos)))
|
||||
(drawOnSprite text canvas pos)))))
|
Reference in New Issue
Block a user