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