Browse Source

Allows y === null in drawText.

Allow leaving Y as null in the dynamicTexture.drawText function and centers the text vertically instead.
aWeirdo 8 years ago
parent
commit
71cb92cfc4
1 changed files with 6 additions and 2 deletions
  1. 6 2
      src/Materials/Textures/babylon.dynamicTexture.ts

+ 6 - 2
src/Materials/Textures/babylon.dynamicTexture.ts

@@ -79,7 +79,11 @@ module BABYLON {
                 var textSize = this._context.measureText(text);
                 x = (size.width - textSize.width) / 2;
             }
-
+            if (y === null) {
+                var fontSize = parseInt((font.replace(/\D/g,'')));;
+                y = (size.height /2) + (fontSize/4);
+            }
+            
             this._context.fillStyle = color;
             this._context.fillText(text, x, y);
 
@@ -103,4 +107,4 @@ module BABYLON {
             return newTexture;
         }
     }
-} 
+}