Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(text, style, canvas)
{
canvas = canvas || document.createElement('canvas');
canvas.width = 3;
canvas.height = 3;
const texture = Texture.from(canvas, settings.SCALE_MODE, 'text');
texture.orig = new Rectangle();
texture.trim = new Rectangle();
super(texture);
// base texture is already automatically added to the cache, now adding the actual texture
Texture.addToCache(this._texture, this._texture.baseTexture.textureCacheIds[0]);
/**
* The canvas element that everything is drawn to
*
* @member {HTMLCanvasElement}
*/
this.canvas = canvas;
*
* @member {HTMLCanvasElement} _canvas
* @private
*/
this._canvas = document.createElement('canvas');
this._canvas.width = 4;
this._canvas.height = this.sampleSize;
/**
* The displacement map is used to generate the bands.
* If using your own texture, `slices` will be ignored.
*
* @member {PIXI.Texture}
* @readonly
*/
this.texture = Texture.from(this._canvas, { scaleMode: SCALE_MODES.NEAREST });
/**
* Internal number of slices
* @member {number}
* @private
*/
this._slices = 0;
// Set slices
this.slices = options.slices;
}
static fromImage(imageId, width, height, options)
{
// Fallback support for crossorigin, scaleMode parameters
if (options && typeof options !== 'object')
{
options = {
scaleMode: arguments[4],
resourceOptions: {
crossorigin: arguments[3],
},
};
}
return new TilingSprite(Texture.from(imageId, options), width, height);
}
static from(source, options)
{
const texture = (source instanceof Texture)
? source
: new Texture.from(source, options);
return new Sprite(texture);
}
set colorMap(colorMap) {
if (!(colorMap instanceof Texture)) {
colorMap = Texture.from(colorMap);
}
if (colorMap && colorMap.baseTexture) {
colorMap.baseTexture.scaleMode = this._scaleMode;
colorMap.baseTexture.mipmap = false;
this._size = colorMap.height;
this._sliceSize = 1 / this._size;
this._slicePixelSize = this._sliceSize / this._size;
this._sliceInnerSize = this._slicePixelSize * (this._size - 1);
this.uniforms._size = this._size;
this.uniforms._sliceSize = this._sliceSize;
this.uniforms._slicePixelSize = this._slicePixelSize;
this.uniforms._sliceInnerSize = this._sliceInnerSize;
this.uniforms.colorMap = colorMap;
static fromFrames(frames)
{
const textures = [];
for (let i = 0; i < frames.length; ++i)
{
textures.push(Texture.from(frames[i]));
}
return new AnimatedSprite(textures);
}
static fromImages(images)
{
const textures = [];
for (let i = 0; i < images.length; ++i)
{
textures.push(Texture.from(images[i]));
}
return new AnimatedSprite(textures);
}
static from(source, width, height)
{
return new TilingSprite(Texture.from(source), width, height);
}
constructor(text, style, canvas)
{
canvas = canvas || document.createElement('canvas');
canvas.width = 3;
canvas.height = 3;
const texture = Texture.from(canvas);
texture.orig = new Rectangle();
texture.trim = new Rectangle();
super(texture);
/**
* The canvas element that everything is drawn to
*
* @member {HTMLCanvasElement}
*/
this.canvas = canvas;
/**
* The canvas 2d context that everything is drawn with
* @member {CanvasRenderingContext2D}
if (!canvasRenderer)
{
canvasRenderer = new CanvasRenderer();
}
this.transform.updateLocalTransform();
this.transform.localTransform.copyTo(tempMatrix);
tempMatrix.invert();
tempMatrix.tx -= bounds.x;
tempMatrix.ty -= bounds.y;
canvasRenderer.render(this, canvasBuffer, true, tempMatrix);
const texture = Texture.from(canvasBuffer.baseTexture._canvasRenderTarget.canvas, {
scaleMode,
});
texture.baseTexture.resolution = resolution;
texture.baseTexture.update();
return texture;
};