Merge pull request #1614 from Xela10001/patch-1

Scalable text and spacing fix
This commit is contained in:
Kade M 2021-08-07 23:16:02 -07:00 committed by GitHub
commit 3af8a1dc4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -47,11 +47,20 @@ class Alphabet extends FlxSpriteGroup
var pastX:Float = 0;
var pastY:Float = 0;
public function new(x:Float, y:Float, text:String = "", ?bold:Bool = false, typed:Bool = false, shouldMove:Bool = false)
// ThatGuy: Variables here to be used later
var xScale:Float;
var yScale:Float;
// ThatGuy: Added 2 more variables, xScale and yScale for resizing text
public function new(x:Float, y:Float, text:String = "", ?bold:Bool = false, typed:Bool = false, shouldMove:Bool = false, xScale:Float = 1, yScale:Float = 1)
{
pastX = x;
pastY = y;
// ThatGuy: Have to assign these variables
this.xScale = xScale;
this.yScale = yScale;
super(x, y);
_finalText = text;
@ -72,7 +81,7 @@ class Alphabet extends FlxSpriteGroup
}
}
public function reType(text)
public function reType(text, xScale:Float = 1, yScale:Float = 1)
{
for (i in listOAlphabets)
remove(i);
@ -87,6 +96,9 @@ class Alphabet extends FlxSpriteGroup
x = pastX;
y = pastY;
this.xScale = xScale;
this.yScale = yScale;
addText();
}
@ -111,17 +123,24 @@ class Alphabet extends FlxSpriteGroup
{
if (lastSprite != null)
{
xPos = lastSprite.x + lastSprite.width;
// ThatGuy: This is the line that fixes the spacing error when the x position of this class's objects was anything other than 0
xPos = lastSprite.x - pastX + lastSprite.width;
}
if (lastWasSpace)
{
xPos += 40;
// ThatGuy: Also this line
xPos += 40 * xScale;
lastWasSpace = false;
}
// var letter:AlphaCharacter = new AlphaCharacter(30 * loopNum, 0);
var letter:AlphaCharacter = new AlphaCharacter(xPos, 0);
// ThatGuy: These are the lines that change the individual scaling of each character
letter.scale.set(xScale, yScale);
letter.updateHitbox();
listOAlphabets.add(letter);
if (isBold)
@ -147,6 +166,7 @@ class Alphabet extends FlxSpriteGroup
public var personTalking:String = 'gf';
// ThatGuy: THIS FUNCTION ISNT CHANGED! Because i dont use it lol
public function startTypedText():Void
{
_finalText = text;
@ -261,6 +281,37 @@ class Alphabet extends FlxSpriteGroup
super.update(elapsed);
}
// ThatGuy: Ooga booga function for resizing text, with the option of wanting it to have the same midPoint
// Side note: Do not, EVER, do updateHitbox() unless you are retyping the whole thing. Don't know why, but the position gets retarded if you do that
public function resizeText(xScale:Float, yScale:Float, xStaysCentered:Bool = true, yStaysCentered:Bool = false):Void {
var oldWidth:Float = this.width;
var oldHeight:Float = this.height;
//trace('old x before scaling: ' + this.x);
//trace('old midpoint before scaling: ' + this.getMidpoint().x);
reType(text, xScale, yScale);
//trace('old x after scaling: ' + this.x);
//trace('old midpoint after scaling: ' + this.getMidpoint().x);
//This works, commenting out all the tracing
if(xStaysCentered) {
/*
If oldX is the old position, that is the same for both sizes of text, e.g. oldX = 50
And oldWidth is the old width of the text, e.g. oldWidth = 100
And newWidth is the current width of the text, e.g. newWidth= 150
And the midpoint, is always the same, e.g. midpoint = oldX + oldWidth/2 = 50 + 100/2 = 100
and the newMidpoint, which is equal to midpoint, is newX + newWidth/2, then
newX = midpoint - newWidth/2 <=> newX = oldX + oldWidth/2 - newWidth/2, e.g., <=> newX = 50 + 100/2 - 150/2 <=> newX = 25
*/
//Since this.x doesnt change with text scaling, in this equation, this.x can be used as both the old and the new x
this.x = this.x + oldWidth/2 - this.width/2;
//trace('new x after scaling: ' + this.x);
//trace('new midpoint after scaling: ' + this.getMidpoint().x);
}
if(yStaysCentered) {
// Same logic applies here
this.y = this.y + oldHeight/2 - this.height/2;
}
}
}
class AlphaCharacter extends FlxSprite
@ -278,7 +329,10 @@ class AlphaCharacter extends FlxSprite
super(x, y);
var tex = Paths.getSparrowAtlas('alphabet');
frames = tex;
antialiasing = FlxG.save.data.antialiasing;
if(FlxG.save.data.antialiasing)
{
antialiasing = true;
}
}
public function createBold(letter:String)