CameraTools.calculateScrollBounds

This commit is contained in:
2022-06-28 04:52:04 +00:00
parent e8a5bafa4d
commit eac74165ae
8 changed files with 38 additions and 16 deletions

View File

@@ -10,6 +10,9 @@ import flixel.math.FlxPoint;
import flixel.FlxSprite;
import flixel.FlxG;
import flixel.util.FlxColor;
import flixel.FlxObject;
import flixel.group.FlxGroup;
import kiss_flixel.GroupTools;
using Lambda;

View File

@@ -80,4 +80,16 @@
if (FlxG.mouse.wheel != 0) {
camera.zoom += (FlxG.mouse.wheel * elapsed * speed);
}
}#)
}#)
(function calculateScrollBounds <>[:FlxObject T] [:FlxCamera camera :FlxTypedGroup<T> group &opt :Float margin]
(let [r (GroupTools.calculateBounds group margin)]
(camera.setScrollBoundsRect r.x r.y r.width r.height)))
(function extendScrollBounds [:FlxCamera camera :FlxObject object &opt :Float margin]
// if the given object is out of bounds, extend the bounds
(let [r (object.getRotatedBounds)]
(setMin camera.minScrollX (- r.left margin))
(setMin camera.minScrollY (- r.top margin))
(setMax camera.maxScrollX (+ r.right margin))
(setMax camera.maxScrollY (+ r.bottom margin))))