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

add x, y and text args to FlxBitmapText #2750

Merged
merged 3 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions flixel/text/FlxBitmapText.hx
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,14 @@ class FlxBitmapText extends FlxSprite
* Warning: The default font may work incorrectly on HTML5
* and is utterly unreliable on Brave Browser with shields up.
*
* @param font Optional parameter for component's font prop
* @param x The initial X position of the text.
* @param y The initial Y position of the text.
* @param text The text to display.
* @param font Optional parameter for component's font prop
*/
public function new(?font:FlxBitmapFont)
public function new(?x = 0.0, ?y = 0.0, ?text:String, ?font:FlxBitmapFont)
{
super();
super(x, y);

width = fieldWidth = 2;
alpha = 1;
Expand All @@ -223,6 +226,8 @@ class FlxBitmapText extends FlxSprite
textDrawData = [];
borderDrawData = [];
}

this.text = text;
}

/**
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/src/flixel/text/FlxBitmapTextTest.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package flixel.text;

import flixel.text.FlxBitmapText;
import flixel.graphics.frames.FlxBitmapFont;
import massive.munit.Assert;

class FlxBitmapTextTest extends FlxTest
{
var text:FlxBitmapText;
Expand All @@ -10,4 +14,19 @@ class FlxBitmapTextTest extends FlxTest
text = new FlxBitmapText();
destroyable = text;
}

@Test // #1526 and #2750
function testCreateSpriteSkipPosition()
{
final text1 = new FlxBitmapText("test");
final text2 = new FlxBitmapText(FlxBitmapFont.getDefaultFont());

Assert.areEqual(0, text1.x);
Assert.areEqual(0, text1.y);
Assert.areEqual(0, text2.x);
Assert.areEqual(0, text2.y);

Assert.isNotNull(text1.text);
Assert.areEqual(text1.font, text2.font);
}
}