The onContextRestored callback won't be defined any more unless the WebGL Renderer is in use in the following objects: BitmapMask, Static Tilemap, TileSprite and Text. This should allow those objects to now work in HEADLESS mode. Fix #3368

This commit is contained in:
Richard Davey 2018-03-12 13:37:13 +00:00
parent 063d30602e
commit edf1aa7cc1
6 changed files with 32 additions and 30 deletions

View file

@ -22,6 +22,8 @@
* The class GameObject has now been exposed, available via `Phaser.GameObjects.GameObject` (thanks @rexrainbow)
* A Camera following a Game Object will now take the zoom factor of the camera into consideration when scrolling. Fix #3353 (thanks @brandonvdongen)
* Calling `setText` on a BitmapText object will now recalculate its display origin values. Fix #3350 (thanks @migiyubi)
* You can now pass an object to Loader.atlas, like you you can with images. Fix #3268 (thanks @TCatshoek)
* The `onContextRestored` callback won't be defined any more unless the WebGL Renderer is in use in the following objects: BitmapMask, Static Tilemap, TileSprite and Text. This should allow those objects to now work in HEADLESS mode. Fix #3368 (thanks @16patsle)
## Version 3.2.0 - Kaori - 5th March 2018

View file

@ -112,7 +112,7 @@ var BitmapMask = new Class({
*/
this.invertAlpha = false;
if (renderer.gl)
if (renderer && renderer.gl)
{
var width = renderer.width;
var height = renderer.height;

View file

@ -8,6 +8,7 @@ var AddToDOM = require('../../../dom/AddToDOM');
var CanvasPool = require('../../../display/canvas/CanvasPool');
var Class = require('../../../utils/Class');
var Components = require('../../components');
var CONST = require('../../../const');
var GameObject = require('../../GameObject');
var GetTextSize = require('../GetTextSize');
var GetValue = require('../../../utils/object/GetValue');
@ -208,13 +209,14 @@ var Text = new Class({
this.setText(text);
var _this = this;
scene.sys.game.renderer.onContextRestored(function ()
if (scene.sys.game.config.renderType === CONST.WEBGL)
{
_this.canvasTexture = null;
_this.dirty = true;
});
scene.sys.game.renderer.onContextRestored(function ()
{
this.canvasTexture = null;
this.dirty = true;
}, this);
}
},
/**

View file

@ -7,6 +7,7 @@
var CanvasPool = require('../../display/canvas/CanvasPool');
var Class = require('../../utils/Class');
var Components = require('../components');
var CONST = require('../../const');
var GameObject = require('../GameObject');
var GetPowerOfTwo = require('../../math/pow2/GetPowerOfTwo');
var TileSpriteRender = require('./TileSpriteRender');
@ -179,13 +180,17 @@ var TileSprite = new Class({
this.updateTileTexture();
scene.sys.game.renderer.onContextRestored(function (renderer)
if (scene.sys.game.config.renderType === CONST.WEBGL)
{
var gl = renderer.gl;
this.tileTexture = null;
this.dirty = true;
this.tileTexture = renderer.createTexture2D(0, gl.LINEAR, gl.LINEAR, gl.REPEAT, gl.REPEAT, gl.RGBA, this.canvasBuffer, this.potWidth, this.potHeight);
}, this);
scene.sys.game.renderer.onContextRestored(function (renderer)
{
var gl = renderer.gl;
this.tileTexture = null;
this.dirty = true;
this.tileTexture = renderer.createTexture2D(0, gl.LINEAR, gl.LINEAR, gl.REPEAT, gl.REPEAT, gl.RGBA, _this.canvasBuffer, _this.potWidth, _this.potHeight);
}, this);
}
},
/**

View file

@ -490,6 +490,7 @@ var WebGLRenderer = new Class({
onContextRestored: function (callback, target)
{
this.restoredContextCallbacks.push([ callback, target ]);
return this;
},

View file

@ -6,6 +6,7 @@
var Class = require('../../utils/Class');
var Components = require('../../gameobjects/components');
var CONST = require('../../const');
var GameObject = require('../../gameobjects/GameObject');
var StaticTilemapLayerRender = require('./StaticTilemapLayerRender');
var TilemapComponents = require('../components');
@ -194,23 +195,14 @@ var StaticTilemapLayer = new Class({
this.initPipeline('TextureTintPipeline');
this.renderer.onContextRestored(this.contextRestore, this);
},
/**
* @method Phaser.Tilemaps.StaticTilemapLayer#contextRestore
* @since 3.0.0
*
* @param {Phaser.Renderer.WebGLRenderer} renderer - The renderer instance.
*
* @return {Phaser.Tilemaps.StaticTilemapLayer} This Tilemap Layer object.
*/
contextRestore: function ()
{
this.dirty = true;
this.vertexBuffer = null;
return this;
if (scene.sys.game.config.renderType === CONST.WEBGL)
{
scene.sys.game.renderer.onContextRestored(function ()
{
this.dirty = true;
this.vertexBuffer = null;
}, this);
}
},
/**