Skip to content

Commit e368c47

Browse files
committed
The TextureManager now generates a new texture with the key __WHITE durings its boot process. This is a pure white 4x4 texture used by the Graphics pipelines.
1 parent 81800e0 commit e368c47

1 file changed

Lines changed: 30 additions & 27 deletions

File tree

src/textures/TextureManager.js

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,16 @@ var TextureManager = new Class({
123123
*/
124124
boot: function ()
125125
{
126-
this._pending = 2;
127-
128126
this.on(Events.LOAD, this.updatePending, this);
129127
this.on(Events.ERROR, this.updatePending, this);
130128

131-
this.addBase64('__DEFAULT', this.game.config.defaultImage);
132-
this.addBase64('__MISSING', this.game.config.missingImage);
129+
var config = this.game.config;
130+
131+
this.addBase64('__DEFAULT', config.defaultImage);
132+
this.addBase64('__MISSING', config.missingImage);
133+
this.addBase64('__WHITE', config.whiteImage);
134+
135+
this._pending = 3;
133136

134137
this.game.events.once(GameEvents.DESTROY, this.destroy, this);
135138
},
@@ -252,7 +255,7 @@ var TextureManager = new Class({
252255
*
253256
* @param {string} key - The unique string-based key of the Texture.
254257
* @param {*} data - The Base64 encoded data.
255-
*
258+
*
256259
* @return {this} This Texture Manager instance.
257260
*/
258261
addBase64: function (key, data)
@@ -287,9 +290,9 @@ var TextureManager = new Class({
287290

288291
/**
289292
* Gets an existing texture frame and converts it into a base64 encoded image and returns the base64 data.
290-
*
293+
*
291294
* You can also provide the image type and encoder options.
292-
*
295+
*
293296
* This will only work with bitmap based texture frames, such as those created from Texture Atlases.
294297
* It will not work with GL Texture objects, such as Shaders, or Render Textures. For those please
295298
* see the WebGL Snapshot function instead.
@@ -301,7 +304,7 @@ var TextureManager = new Class({
301304
* @param {(string|integer)} [frame] - The string-based name, or integer based index, of the Frame to get from the Texture.
302305
* @param {string} [type='image/png'] - A DOMString indicating the image format. The default format type is image/png.
303306
* @param {number} [encoderOptions=0.92] - A Number between 0 and 1 indicating the image quality to use for image formats that use lossy compression such as image/jpeg and image/webp. If this argument is anything else, the default value for image quality is used. The default value is 0.92. Other arguments are ignored.
304-
*
307+
*
305308
* @return {string} The base64 encoded data, or an empty string if the texture frame could not be found.
306309
*/
307310
getBase64: function (key, frame, type, encoderOptions)
@@ -374,15 +377,15 @@ var TextureManager = new Class({
374377

375378
this.emit(Events.ADD, key, texture);
376379
}
377-
380+
378381
return texture;
379382
},
380383

381384
/**
382385
* Takes a WebGL Texture and creates a Phaser Texture from it, which is added to the Texture Manager using the given key.
383-
*
386+
*
384387
* This allows you to then use the Texture as a normal texture for texture based Game Objects like Sprites.
385-
*
388+
*
386389
* This is a WebGL only feature.
387390
*
388391
* @method Phaser.Textures.TextureManager#addGLTexture
@@ -408,7 +411,7 @@ var TextureManager = new Class({
408411

409412
this.emit(Events.ADD, key, texture);
410413
}
411-
414+
412415
return texture;
413416
},
414417

@@ -437,17 +440,17 @@ var TextureManager = new Class({
437440

438441
this.emit(Events.ADD, key, texture);
439442
}
440-
443+
441444
return texture;
442445
},
443446

444447
/**
445448
* Creates a new Texture using the given config values.
446-
*
449+
*
447450
* Generated textures consist of a Canvas element to which the texture data is drawn.
448-
*
451+
*
449452
* Generates a texture based on the given Create configuration object.
450-
*
453+
*
451454
* The texture is drawn using a fixed-size indexed palette of 16 colors, where the hex value in the
452455
* data cells map to a single color. For example, if the texture config looked like this:
453456
*
@@ -466,14 +469,14 @@ var TextureManager = new Class({
466469
* '.27887.78872.',
467470
* '.787.....787.'
468471
* ];
469-
*
472+
*
470473
* this.textures.generate('star', { data: star, pixelWidth: 4 });
471474
* ```
472-
*
475+
*
473476
* Then it would generate a texture that is 52 x 48 pixels in size, because each cell of the data array
474477
* represents 1 pixel multiplied by the `pixelWidth` value. The cell values, such as `8`, maps to color
475478
* number 8 in the palette. If a cell contains a period character `.` then it is transparent.
476-
*
479+
*
477480
* The default palette is Arne16, but you can specify your own using the `palette` property.
478481
*
479482
* @method Phaser.Textures.TextureManager#generate
@@ -717,7 +720,7 @@ var TextureManager = new Class({
717720
if (this.checkKey(key))
718721
{
719722
texture = this.create(key, source);
720-
723+
721724
Parser.AtlasXML(texture, 0, data);
722725

723726
if (dataSource)
@@ -899,11 +902,11 @@ var TextureManager = new Class({
899902

900903
/**
901904
* Returns a Texture from the Texture Manager that matches the given key.
902-
*
905+
*
903906
* If the key is `undefined` it will return the `__DEFAULT` Texture.
904-
*
907+
*
905908
* If the key is an instance of a Texture, it will return the key directly.
906-
*
909+
*
907910
* Finally. if the key is given, but not found and not a Texture instance, it will return the `__MISSING` Texture.
908911
*
909912
* @method Phaser.Textures.TextureManager#get
@@ -1076,9 +1079,9 @@ var TextureManager = new Class({
10761079

10771080
ctx.clearRect(0, 0, 1, 1);
10781081
ctx.drawImage(textureFrame.source.image, x, y, 1, 1, 0, 0, 1, 1);
1079-
1082+
10801083
var rgb = ctx.getImageData(0, 0, 1, 1);
1081-
1084+
10821085
return rgb.data[3];
10831086
}
10841087
}
@@ -1112,9 +1115,9 @@ var TextureManager = new Class({
11121115

11131116
/**
11141117
* Changes the key being used by a Texture to the new key provided.
1115-
*
1118+
*
11161119
* The old key is removed, allowing it to be re-used.
1117-
*
1120+
*
11181121
* Game Objects are linked to Textures by a reference to the Texture object, so
11191122
* all existing references will be retained.
11201123
*

0 commit comments

Comments
 (0)