How to use the @pixi/core.Texture.from function in @pixi/core

To help you get started, we’ve selected a few @pixi/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pixijs / pixi.js / packages / text / src / Text.js View on Github external
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;
github pixijs / pixi-filters / filters / glitch / src / GlitchFilter.js View on Github external
*
         * @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;
    }
github pixijs / pixi.js / packages / sprite-tiling / src / TilingSprite.js View on Github external
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);
    }
github pixijs / pixi.js / packages / sprite / src / Sprite.js View on Github external
static from(source, options)
    {
        const texture = (source instanceof Texture)
            ? source
            : new Texture.from(source, options);

        return new Sprite(texture);
    }
github pixijs / pixi-filters / filters / color-map / src / ColorMapFilter.js View on Github external
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;
github pixijs / pixi.js / packages / sprite-animated / src / AnimatedSprite.js View on Github external
static fromFrames(frames)
    {
        const textures = [];

        for (let i = 0; i < frames.length; ++i)
        {
            textures.push(Texture.from(frames[i]));
        }

        return new AnimatedSprite(textures);
    }
github pixijs / pixi.js / packages / sprite-animated / src / AnimatedSprite.js View on Github external
static fromImages(images)
    {
        const textures = [];

        for (let i = 0; i < images.length; ++i)
        {
            textures.push(Texture.from(images[i]));
        }

        return new AnimatedSprite(textures);
    }
github pixijs / pixi.js / packages / sprite-tiling / src / TilingSprite.js View on Github external
static from(source, width, height)
    {
        return new TilingSprite(Texture.from(source), width, height);
    }
github pixijs / pixi.js / packages / text / src / Text.js View on Github external
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}
github pixijs / pixi.js / packages / canvas / canvas-graphics / src / Graphics.js View on Github external
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;
};