@@ -29,6 +29,7 @@ var TextStyle = require('../TextStyle');
2929 * @extends Phaser.GameObjects.Components.Alpha
3030 * @extends Phaser.GameObjects.Components.BlendMode
3131 * @extends Phaser.GameObjects.Components.ComputedSize
32+ * @extends Phaser.GameObjects.Components.Crop
3233 * @extends Phaser.GameObjects.Components.Depth
3334 * @extends Phaser.GameObjects.Components.Flip
3435 * @extends Phaser.GameObjects.Components.GetBounds
@@ -55,6 +56,7 @@ var Text = new Class({
5556 Components . Alpha ,
5657 Components . BlendMode ,
5758 Components . ComputedSize ,
59+ Components . Crop ,
5860 Components . Depth ,
5961 Components . Flip ,
6062 Components . GetBounds ,
@@ -78,6 +80,15 @@ var Text = new Class({
7880
7981 GameObject . call ( this , scene , 'Text' ) ;
8082
83+ /**
84+ * The renderer in use by this Text object.
85+ *
86+ * @name Phaser.GameObjects.Text#renderer
87+ * @type {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer) }
88+ * @since 3.12.0
89+ */
90+ this . renderer = scene . sys . game . renderer ;
91+
8192 this . setPosition ( x , y ) ;
8293 this . setOrigin ( 0 , 0 ) ;
8394 this . initPipeline ( 'TextureTintPipeline' ) ;
@@ -171,16 +182,6 @@ var Text = new Class({
171182 */
172183 this . height = 1 ;
173184
174- /**
175- * The Canvas Texture that the text is rendered to for WebGL rendering.
176- *
177- * @name Phaser.GameObjects.Text#canvasTexture
178- * @type {HTMLCanvasElement }
179- * @default null
180- * @since 3.0.0
181- */
182- this . canvasTexture = null ;
183-
184185 /**
185186 * Whether the text or its settings have changed and need updating.
186187 *
@@ -197,6 +198,34 @@ var Text = new Class({
197198 this . style . resolution = scene . sys . game . config . resolution ;
198199 }
199200
201+ /**
202+ * The internal crop data object, as used by `setCrop` and passed to the `Frame.setCropUVs` method.
203+ *
204+ * @name Phaser.GameObjects.Text#_crop
205+ * @type {object }
206+ * @private
207+ * @since 3.12.0
208+ */
209+ this . _crop = this . resetCropObject ( ) ;
210+
211+ // Create a Texture for this Text object
212+ this . texture = scene . sys . textures . addCanvas ( null , this . canvas , true ) ;
213+
214+ // Get the frame
215+ this . frame = this . texture . get ( ) ;
216+
217+ // Set the resolution
218+ this . frame . source . resolution = this . style . resolution ;
219+
220+ if ( this . renderer && this . renderer . gl )
221+ {
222+ // Clear the default 1x1 glTexture, as we override it later
223+
224+ this . renderer . deleteTexture ( this . frame . source . glTexture ) ;
225+
226+ this . frame . source . glTexture = null ;
227+ }
228+
200229 this . initRTL ( ) ;
201230
202231 if ( style && style . padding )
@@ -215,7 +244,6 @@ var Text = new Class({
215244 {
216245 scene . sys . game . renderer . onContextRestored ( function ( )
217246 {
218- this . canvasTexture = null ;
219247 this . dirty = true ;
220248 } , this ) ;
221249 }
@@ -1014,6 +1042,9 @@ var Text = new Class({
10141042 {
10151043 canvas . width = w ;
10161044 canvas . height = h ;
1045+
1046+ this . frame . setSize ( w , h ) ;
1047+
10171048 style . syncFont ( canvas , context ) ; // Resizing resets the context
10181049 }
10191050 else
@@ -1088,6 +1119,12 @@ var Text = new Class({
10881119
10891120 context . restore ( ) ;
10901121
1122+ if ( this . renderer . gl )
1123+ {
1124+ this . frame . source . glTexture = this . renderer . canvasToTexture ( canvas , this . frame . source . glTexture ) ;
1125+ this . frame . glTexture = this . frame . source . glTexture ;
1126+ }
1127+
10911128 this . dirty = true ;
10921129
10931130 return this ;
@@ -1152,6 +1189,8 @@ var Text = new Class({
11521189 }
11531190
11541191 CanvasPool . remove ( this . canvas ) ;
1192+
1193+ this . texture . destroy ( ) ;
11551194 }
11561195
11571196} ) ;
0 commit comments