From 83d694416e8bb6aaa1f43d3731486aee5fd98439 Mon Sep 17 00:00:00 2001 From: Xela10001 <47480171+Xela10001@users.noreply.github.com> Date: Fri, 6 Aug 2021 11:08:56 +0100 Subject: [PATCH 1/2] Scalable text and spacing fix Added functionality for resizing text using the xScale and yScale arguments of new Alphabet(). Fixed backwards sentences when the x variable was negative and fixed spacing error when x was positive (Basically, the letters bug out if the x in new Alphabet(x, y, text) was anything other than 0). --- source/Alphabet.hx | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/source/Alphabet.hx b/source/Alphabet.hx index e376150..81e18a5 100644 --- a/source/Alphabet.hx +++ b/source/Alphabet.hx @@ -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; @@ -111,17 +120,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 +163,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; @@ -278,7 +295,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) From 7b97080e38735bc48853d44085f9bae5a6629848 Mon Sep 17 00:00:00 2001 From: Xela10001 <47480171+Xela10001@users.noreply.github.com> Date: Fri, 6 Aug 2021 22:07:01 +0100 Subject: [PATCH 2/2] Added resizing existing text Added a function called resizeText, which can be used on already existing text to make it bigger or smaller, and even has a boolean incase you want the text to keep its midpoint or not. --- source/Alphabet.hx | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/source/Alphabet.hx b/source/Alphabet.hx index 81e18a5..dc3484a 100644 --- a/source/Alphabet.hx +++ b/source/Alphabet.hx @@ -81,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); @@ -95,6 +95,9 @@ class Alphabet extends FlxSpriteGroup listOAlphabets.clear(); x = pastX; y = pastY; + + this.xScale = xScale; + this.yScale = yScale; addText(); } @@ -278,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