Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const context = renderer.context;
const transform = this.worldTransform;
const res = renderer.resolution;
const isTinted = this.tint !== 0xFFFFFF;
const texture = this.texture;
// Work out tinting
if (isTinted)
{
if (this._cachedTint !== this.tint)
{
// Tint has changed, need to update the tinted texture and use that instead
this._cachedTint = this.tint;
this._tintedCanvas = canvasUtils.getTintedCanvas(this, this.tint);
}
}
const textureSource = !isTinted ? texture.baseTexture.source : this._tintedCanvas;
if (!this._canvasUvs)
{
this._canvasUvs = [0, 0, 0, 0, 0, 0, 0, 0];
}
const vertices = this.vertices;
const uvs = this._canvasUvs;
const u0 = isTinted ? 0 : texture.frame.x;
const v0 = isTinted ? 0 : texture.frame.y;
const u1 = u0 + texture.frame.width;
const v1 = v0 + texture.frame.height;
const modX = ((this.tilePosition.x / this.tileScale.x) % texture._frame.width) * baseTextureResolution;
const modY = ((this.tilePosition.y / this.tileScale.y) % texture._frame.height) * baseTextureResolution;
// create a nice shiny pattern!
if (this._textureID !== this._texture._updateID || this._cachedTint !== this.tint)
{
this._textureID = this._texture._updateID;
// cut an object from a spritesheet..
const tempCanvas = new CanvasRenderTarget(texture._frame.width,
texture._frame.height,
baseTextureResolution);
// Tint the tiling sprite
if (this.tint !== 0xFFFFFF)
{
this._tintedCanvas = canvasUtils.getTintedCanvas(this, this.tint);
tempCanvas.context.drawImage(this._tintedCanvas, 0, 0);
}
else
{
tempCanvas.context.drawImage(source,
-texture._frame.x * baseTextureResolution, -texture._frame.y * baseTextureResolution);
}
this._cachedTint = this.tint;
this._canvasPattern = tempCanvas.context.createPattern(tempCanvas.canvas, 'repeat');
}
// set context state..
context.globalAlpha = this.worldAlpha;
context.setTransform(transform.a * resolution,
transform.b * resolution,
transform.c * resolution,