Skip to content

Commit 370d5ed

Browse files
authored
Better mouse overlapping function for CoolUtil (#813)
* mouseOverlaps * This makes more sense yeah thinking of not even allowing disjointed overlap checks keeping it for now * oops forgot to define that var as flxcamera
1 parent d7dbe50 commit 370d5ed

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

source/funkin/backend/utils/CoolUtil.hx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ final class CoolUtil
880880
*/
881881
public static inline function browsePath(path:String) {
882882
var formattedPath:String = Path.normalize(path);
883-
883+
884884
#if windows
885885
formattedPath = formattedPath.replace("/", "\\");
886886
Sys.command("explorer", [formattedPath]);
@@ -1027,6 +1027,20 @@ final class CoolUtil
10271027
return result;
10281028
}
10291029

1030+
/**
1031+
* Returns if the mouse is overlapping the sprite on a given camera, taking the camera's position, scroll and zoom into account.
1032+
*
1033+
* @param sprite Any `FlxBasic`
1034+
* @param camera The camera you want to check overlap on. Uses the sprite's camera by default.
1035+
* @return Bool
1036+
*/
1037+
public static function mouseOverlaps(sprite:FlxBasic, ?camera:FlxCamera) {
1038+
var camToCheck:FlxCamera = camera ?? sprite.camera;
1039+
var posthing:FlxPoint = FlxG.mouse.getWorldPosition(camToCheck);
1040+
1041+
return posthing != null && FlxMath.inBounds(posthing.x, sprite.x, sprite.x + sprite.width) && FlxMath.inBounds(posthing.y, sprite.y, sprite.y + sprite.height);
1042+
}
1043+
10301044
/**
10311045
* Sorts an array alphabetically.
10321046
* @param array Array to sort
@@ -1077,7 +1091,7 @@ final class CoolUtil
10771091
r.add(str);
10781092
return r.toString();
10791093
}
1080-
1094+
10811095
public static inline function bound(Value:Float, Min:Float, Max:Float):Float {
10821096
#if cpp
10831097
var _hx_tmp1:Float = Value;
@@ -1224,8 +1238,8 @@ final class CoolUtil
12241238

12251239
/**
12261240
* ! REQUIRES FULL PATH!!!
1227-
* @param path
1228-
* @return Bool
1241+
* @param path
1242+
* @return Bool
12291243
*/
12301244
public static function imageHasFrameData(path:String):String {
12311245
if (FileSystem.exists(Path.withExtension(path, "xml"))) return "xml";

0 commit comments

Comments
 (0)