CameraTools/GroupTools bugfixing and sprite scale support

This commit is contained in:
2022-08-02 02:24:22 +00:00
parent 744f99bc46
commit 9e8036deb2
6 changed files with 192 additions and 152 deletions

View File

@@ -8,20 +8,22 @@
(group.remove obj)
(group.insert 0 obj)))
(function :FlxRect calculateBounds <>[:FlxObject T] [:FlxTypedGroup<T> group &opt :Float margin]
(function :FlxRect calculateScreenBounds <>[:FlxSprite T] [:FlxTypedGroup<T> group &opt :FlxCamera camera :Float margin]
(unless margin (set margin 0))
(let [&mut minX 0
&mut maxX 0
&mut minY 0
&mut maxY 0
r (new FlxRect)]
(let [s (group.getFirstAlive)
r (new FlxRect)
bounds (s.getScreenBounds r camera)
&mut minX bounds.left
&mut maxX bounds.right
&mut minY bounds.top
&mut maxY bounds.bottom]
(group.forEach ->object
(let [bounds (object.getRotatedBounds r)]
(set minX (min minX bounds.left))
(set minY (min minY bounds.top))
(set maxX (max maxX bounds.right))
(set maxY (max maxY bounds.bottom))))
(group.forEach ->sprite
(let [bounds (sprite.getScreenBounds r camera)]
(setMin minX bounds.left)
(setMin minY bounds.top)
(setMax maxX bounds.right)
(setMax maxY bounds.bottom)))
(r.fromTwoPoints
(new FlxPoint (- minX margin) (- minY margin))