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

Honor scale in FlxBitmapText width and height, add setCharFrame #3037

Merged
merged 2 commits into from
Feb 24, 2024

Conversation

Geokureli
Copy link
Member

@Geokureli Geokureli commented Feb 17, 2024

  1. Adds setCharFrame to allow the adjustment of char frames after it's created, all the methods in FlxBitmapFont are private making it hard to make custom fonts via code, example, currently I have the following code in a project:
static function createFont()
{
	final font = FlxBitmapFont.fromMonospace(AssetPaths.font__png, "", new FlxPoint(8, 8));
	
	final chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!";
	final widths = ['I'.code=>3, '!'.code=>3, 'T'.code=>7];
	var x:Int = 0;
	for (i in 0...chars.length)
	{
		final charCode = chars.charCodeAt(i);
		final width = widths.exists(charCode) ? widths[charCode] : 8;
		final frame = FlxRect.get(x, 0, width, 8);
		@:privateAccess
		font.addCharFrame(charCode, frame, FlxPoint.weak(), width);
		x += width;
	}
	return font;
}

I shouldn't need to use @:privateAccess to adjust a few chars. We could add a new arg to fromMonospace (or make a new func) that takes a map of widths and a default width, but we should really expose some of these methods, anyway

  1. when you scale up a bitmap text and call updateHitbox the width/height is set to the correct value, but anytime you change something it gets set back to the frameWidth/frameHeight. This will honor scale whenever it sets width and height. Ideally it shouldn't set width and height ever, only frameWidth and frameHeight because w/h are used for collision but thats an old ass problem I don't want to fix now

@Geokureli Geokureli added this to the 5.7.0 milestone Feb 21, 2024
@Geokureli Geokureli added the Text label Feb 21, 2024
@Geokureli Geokureli merged commit 986d57b into HaxeFlixel:dev Feb 24, 2024
16 checks passed
@Geokureli Geokureli deleted the bitmaptext-size branch February 24, 2024 02:38
Geokureli added a commit that referenced this pull request Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant