flixel icon indicating copy to clipboard operation
flixel copied to clipboard

Add FlxG.centerGraphic() and camera.centerGraphic()

Open richTrash21 opened this issue 11 months ago • 6 comments

Closes #3309

Another attempt at #3310 based on Geokureli's suggestion.

Adds FlxG.centerGraphic() and camera.centerGraphic() for centering sprites by their graphic size and FlxG.centerHitbox() and camera.centerHitbox() for centering objects by their hitbox size.

To Do

  • [x] Fix inconsistent behaviour of FlxG.centerGraphic() and camera.centerGraphic() on sprites with pixelPerfectPosition or pixelPerfectRender flags set to true.
  • [x] Fix unit tests, FlxGTest.testCenterGraphic() and FlxCameraTest.testCenterGraphic() are failing on rotated sprites for seemingly no reason.
  • [ ] Add docs for new methods.

richTrash21 avatar Jan 03 '25 00:01 richTrash21

I'm not really sure if reflection in c++ works when using generics.

Because both FlxG.random.shuffle and FlxG.random.getObject both don't exist in reflection due to generics

NeeEoo avatar Jan 03 '25 06:01 NeeEoo

I'm not really sure if reflection in c++ works when using generics.

Because both FlxG.random.shuffle and FlxG.random.getObject both don't exist in reflection due to generics

As far as i know the reason why FlxG.random.shuffle and FlxG.random.getObject doesn't exist in reflection is due to @:generic metadata.

I've also made a small test to confirm that:

class Main {
	static function main() {
		var stringField:String;
		var intField:Int;
		var floatField:Float;

		stringField = test1("some string");
		intField = test1(30);
		floatField = test1(1.0034);

		stringField = test2("some string");
		intField = test2(30);
		floatField = test2(1.0034);

		trace(Reflect.getProperty(Main, "test1")); // returns test1 function
		trace(Reflect.getProperty(Main, "test2")); // returns null
	}

	static function test1<T>(v:T):T {
		trace("test generic func #1 (" + Std.string(v) + ")");
		return v;
	}

	@:generic
	static function test2<T>(v:T):T {
		trace("test generic func #2 (" + Std.string(v) + ")");
		return v;
	}
}

richTrash21 avatar Jan 03 '25 15:01 richTrash21

Damn, i wonder why haxe wouldn't generate a base one for reflection purposes

NeeEoo avatar Jan 03 '25 15:01 NeeEoo

Fixed the shaking issue by adding "accurate" methods for getting sprite bounds which does not honor pixelPerfect properties.

richTrash21 avatar Jul 16 '25 09:07 richTrash21

Sorry, but this PR is gonna be put on hold for a bit, I have some relevant changes that need to go in first, though I'm a bit swamped with work atm

Geokureli avatar Jul 16 '25 16:07 Geokureli

Fixed the shaking issue by adding "accurate" methods for getting sprite bounds which does not honor pixelPerfect properties.

Alternatively we can deprecate getScreenBounds in favor of getViewBounds that will have honorPixelPerfect argument. Just no longer like solution that i provided. Thoughts? (no hurry btw!)

richTrash21 avatar Aug 04 '25 12:08 richTrash21