Skip to content

Commit df3c684

Browse files
committed
PIXI.BaseTexture.forceLoaded allows you to set a BaseTexture as loaded, with the given width and height. It then calls BaseTexture.dirty. This is important for when you don't want to modify the shape of the source object by forcing in complete or dimension properties it may not naturally have, but still wish to use it as a base texture.
1 parent 3f51463 commit df3c684

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ Version 2.4 - "Katar" - in dev
300300
* SoundManager.usingWebAudio is set to `false` by default (used to be `true`) and is only explicitly set if Web Audio is available and hasn't been disabled in the PhaserGlobal object.
301301
* SoundManager.touchLocked is now set to `false` should the device be using legacy Audio, avoiding the unlock call running without need.
302302
* Added `type` parameter to `VideoTexture.fromUrl` allowing you to define the mime-type of the video file, which is required for Firefox and Safari in most cases.
303+
* PIXI.BaseTexture.forceLoaded allows you to set a BaseTexture as loaded, with the given width and height. It then calls `BaseTexture.dirty`. This is important for when you don't want to modify the shape of the source object by forcing in `complete` or dimension properties it may not naturally have, but still wish to use it as a base texture.
303304

304305
### Bug Fixes
305306

src/pixi/textures/BaseTexture.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,12 @@ PIXI.BaseTexture = function(source, scaleMode)
105105
*/
106106
this._dirty = [true, true, true, true];
107107

108-
if(!source)return;
108+
if (!source)
109+
{
110+
return;
111+
}
109112

110-
if((this.source.complete || this.source.getContext) && this.source.width && this.source.height)
113+
if ((this.source.complete || this.source.getContext) && this.source.width && this.source.height)
111114
{
112115
this.hasLoaded = true;
113116
this.width = this.source.naturalWidth || this.source.width;
@@ -153,14 +156,32 @@ PIXI.BaseTexture = function(source, scaleMode)
153156
PIXI.BaseTexture.prototype.constructor = PIXI.BaseTexture;
154157
PIXI.EventTarget.mixin(PIXI.BaseTexture.prototype);
155158

159+
/**
160+
* Forces this BaseTexture to be set as loaded, with the given width and height.
161+
* Then calls BaseTexture.dirty.
162+
* Important for when you don't want to modify the source object by forcing in `complete` or dimension properties it may not have.
163+
*
164+
* @method forceLoaded
165+
* @param {number} width - The new width to force the BaseTexture to be.
166+
* @param {number} height - The new height to force the BaseTexture to be.
167+
*/
168+
PIXI.BaseTexture.prototype.forceLoaded = function(width, height)
169+
{
170+
this.hasLoaded = true;
171+
this.width = width;
172+
this.height = height;
173+
this.dirty();
174+
175+
};
176+
156177
/**
157178
* Destroys this base texture
158179
*
159180
* @method destroy
160181
*/
161182
PIXI.BaseTexture.prototype.destroy = function()
162183
{
163-
if(this.imageUrl)
184+
if (this.imageUrl)
164185
{
165186
delete PIXI.BaseTextureCache[this.imageUrl];
166187
delete PIXI.TextureCache[this.imageUrl];

0 commit comments

Comments
 (0)