瀏覽代碼

Adding clear to DynamicTexture

David Catuhe 10 年之前
父節點
當前提交
315f746bac

+ 3 - 3
Babylon/Bones/babylon.bone.ts

@@ -6,9 +6,9 @@
         private _skeleton: Skeleton;
         private _matrix: Matrix;
         private _baseMatrix: Matrix;
-        private _worldTransform = new BABYLON.Matrix();
-        private _absoluteTransform = new BABYLON.Matrix();
-        private _invertedAbsoluteTransform = new BABYLON.Matrix();
+        private _worldTransform = new Matrix();
+        private _absoluteTransform = new Matrix();
+        private _invertedAbsoluteTransform = new Matrix();
         private _parent: Bone;
 
         constructor(public name: string, skeleton: Skeleton, parentBone: Bone, matrix: Matrix) {

+ 11 - 3
Babylon/Materials/Textures/babylon.dynamicTexture.js

@@ -64,11 +64,17 @@ var BABYLON;
             return this._context;
         };
 
+        DynamicTexture.prototype.clear = function () {
+            var size = this.getSize();
+            this._context.fillRect(0, 0, size.width, size.height);
+        };
+
         DynamicTexture.prototype.update = function (invertY) {
             this.getScene().getEngine().updateDynamicTexture(this._texture, this._canvas, invertY === undefined ? true : invertY);
         };
 
-        DynamicTexture.prototype.drawText = function (text, x, y, font, color, clearColor, invertY) {
+        DynamicTexture.prototype.drawText = function (text, x, y, font, color, clearColor, invertY, update) {
+            if (typeof update === "undefined") { update = true; }
             var size = this.getSize();
             if (clearColor) {
                 this._context.fillStyle = clearColor;
@@ -84,12 +90,14 @@ var BABYLON;
             this._context.fillStyle = color;
             this._context.fillText(text, x, y);
 
-            this.update(invertY);
+            if (update) {
+                this.update(invertY);
+            }
         };
 
         DynamicTexture.prototype.clone = function () {
             var textureSize = this.getSize();
-            var newTexture = new BABYLON.DynamicTexture(this.name, textureSize.width, this.getScene(), this._generateMipMaps);
+            var newTexture = new DynamicTexture(this.name, textureSize.width, this.getScene(), this._generateMipMaps);
 
             // Base texture
             newTexture.hasAlpha = this.hasAlpha;

+ 12 - 5
Babylon/Materials/Textures/babylon.dynamicTexture.ts

@@ -9,8 +9,8 @@
 
             this.name = name;
 
-            this.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
-            this.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
+            this.wrapU = Texture.CLAMP_ADDRESSMODE;
+            this.wrapV = Texture.CLAMP_ADDRESSMODE;
 
             this._generateMipMaps = generateMipMaps;
 
@@ -56,11 +56,16 @@
             return this._context;
         }
 
+        public clear(): void {
+            var size = this.getSize();
+            this._context.fillRect(0, 0, size.width, size.height);
+        }
+
         public update(invertY?: boolean): void {
             this.getScene().getEngine().updateDynamicTexture(this._texture, this._canvas, invertY === undefined ? true : invertY);
         }
 
-        public drawText(text: string, x: number, y: number, font: string, color: string, clearColor: string, invertY?: boolean) {
+        public drawText(text: string, x: number, y: number, font: string, color: string, clearColor: string, invertY?: boolean, update = true) {
             var size = this.getSize();
             if (clearColor) {
                 this._context.fillStyle = clearColor;
@@ -76,12 +81,14 @@
             this._context.fillStyle = color;
             this._context.fillText(text, x, y);
 
-            this.update(invertY);
+            if (update) {
+                this.update(invertY);
+            }
         }
 
         public clone(): DynamicTexture {
             var textureSize = this.getSize();
-            var newTexture = new BABYLON.DynamicTexture(this.name, textureSize.width, this.getScene(), this._generateMipMaps);
+            var newTexture = new DynamicTexture(this.name, textureSize.width, this.getScene(), this._generateMipMaps);
 
             // Base texture
             newTexture.hasAlpha = this.hasAlpha;

文件差異過大導致無法顯示
+ 30723 - 19
babylon.2.0-alpha.debug.js


文件差異過大導致無法顯示
+ 19 - 30715
babylon.2.0-alpha.js


+ 2 - 1
babylon.2.0.d.ts

@@ -2102,8 +2102,9 @@ declare module BABYLON {
         public canRescale : boolean;
         public scale(ratio: number): void;
         public getContext(): CanvasRenderingContext2D;
+        public clear(): void;
         public update(invertY?: boolean): void;
-        public drawText(text: string, x: number, y: number, font: string, color: string, clearColor: string, invertY?: boolean): void;
+        public drawText(text: string, x: number, y: number, font: string, color: string, clearColor: string, invertY?: boolean, update?: boolean): void;
         public clone(): DynamicTexture;
     }
 }