Pārlūkot izejas kodu

Text2D multiline starting location is now correct (#1195)

* Change text drawing starting location to the right place in case of multi-line

* Fix textSize null case
Loïc Baumann 9 gadi atpakaļ
vecāks
revīzija
58f87f3187
1 mainītis faili ar 4 papildinājumiem un 1 dzēšanām
  1. 4 1
      src/Canvas2d/babylon.text2d.ts

+ 4 - 1
src/Canvas2d/babylon.text2d.ts

@@ -181,8 +181,9 @@
             if (!this._textSize) {
                 if (this.owner) {
                     let newSize = this.fontTexture.measureText(this._text, this._tabulationSize);
-                    if (newSize !== this._textSize) {
+                    if (!newSize.equals(this._textSize)) {
                         this.onPrimitivePropertyDirty(Prim2DBase.sizeProperty.flagId);
+                        this._positioningDirty();
                     }
                     this._textSize = newSize;
                 } else {
@@ -358,6 +359,8 @@
                 let texture = this.fontTexture;
                 let ts = texture.getSize();
                 let offset = Vector2.Zero();
+                let lh = this.fontTexture.lineHeight;
+                offset.y = ((this.textSize.height/lh)-1) * lh;  // Origin is bottom, not top, so the offset is starting with a y that is the top location of the text
                 let charxpos = 0;
                 d.dataElementCount = this._charCount;
                 d.curElement = 0;