Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FlxPointer.overlaps with different cameras #2885

Merged
merged 1 commit into from
Aug 9, 2023

Conversation

Starmapo
Copy link
Contributor

@Starmapo Starmapo commented Aug 7, 2023

This fixes pointer overlaps when using a camera that isn't the global one.
Currently, it uses the pointer's position in the global camera (getPosition), which won't work properly when using another one unless its properties are the exact same.

Code to reproduce this issue:

import flixel.FlxCamera;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.text.FlxText;

class PlayState extends FlxState
{
	var hudCamera:FlxCamera;
	var spr:FlxSprite;
	var text:FlxText;

	override public function create()
	{
		hudCamera = new FlxCamera(0, 0, Std.int(FlxG.width * 0.25), Std.int(FlxG.height * 0.25));
		hudCamera.setPosition(FlxG.width - hudCamera.width, FlxG.height - hudCamera.height);
		hudCamera.bgColor = flixel.util.FlxColor.GRAY;
		FlxG.cameras.add(hudCamera, false);

		add(spr = new FlxSprite());
		spr.cameras = [hudCamera];

		add(text = new FlxText(5, 5, FlxG.width - 10, '', 16));

		super.create();
	}

	override public function update(elapsed:Float)
	{
		super.update(elapsed);

		text.text = FlxG.mouse.overlaps(spr, hudCamera) ? "Overlapping" : "Not overlapping";
	}
}

@Geokureli Geokureli merged commit fb9907e into HaxeFlixel:dev Aug 9, 2023
@Geokureli
Copy link
Member

thanks!

@Geokureli Geokureli added this to the 5.4.0 milestone Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants