PokéRogue
    Preparing search index...

    A Texture Source is the encapsulation of the actual source data for a Texture.

    It wraps the raw pixel data — typically an Image Element loaded from the file system or network, a Canvas Element, or a Video Element — and manages the corresponding WebGL texture object used by the renderer. In WebGL mode, the TextureSource creates and owns the WebGLTextureWrapper that is uploaded to the GPU.

    You will not usually create a TextureSource directly. Instead, it is created automatically when a Texture is added to the Texture Manager. You can access it via Texture.source, which is an array of TextureSource instances. Most textures have a single source, but multi-atlas textures can have several.

    A Texture can contain multiple Texture Sources, which only happens when a multi-atlas is loaded.

    Index
    • Parameters

      • texture: Texture

        The Texture this TextureSource belongs to.

      • source: TextureSource

        The source image data.

      • Optionalwidth: number

        Optional width of the source image. If not given it's derived from the source itself.

      • Optionalheight: number

        Optional height of the source image. If not given it's derived from the source itself.

      • OptionalflipY: boolean

        Sets the UNPACK_FLIP_Y_WEBGL flag the WebGL Texture uses during upload. Default true.

      Returns TextureSource

    compressionAlgorithm: number

    Holds the compressed texture algorithm, or null if it's not a compressed texture.

    Prior to Phaser 3.60 this value always held null.

    flipY: boolean

    Whether the UNPACK_FLIP_Y_WEBGL flag is set on this WebGL Texture during upload. When true, the texture data is flipped vertically as it is uploaded to the GPU.

    glTexture: WebGLTextureWrapper | null

    The wrapped WebGL Texture of the source image. If this TextureSource is driven from a WebGLTexture already, then this wrapper contains a reference to that WebGLTexture.

    height: number

    The height of the source image. If not specified in the constructor it will check the naturalHeight, videoHeight, and then height properties of the source image.

    image: TextureSourceElement | null

    The image data.

    This is either an Image element, Canvas element, Video Element, or null if the source is not an HTMLElement. Non-HTMLElement sources include compressed textures, data arrays, and references to other WebGL textures.

    isCanvas: boolean

    Is the source image a Canvas Element?

    isGLTexture: boolean

    Is the source image a WebGLTextureWrapper?

    isPowerOf2: boolean

    Are the source image dimensions a power of two?

    isRenderTexture: boolean

    Is the source image a Render Texture?

    isVideo: boolean

    Is the source image a Video Element?

    A reference to the Canvas or WebGL Renderer.

    resolution: number

    The resolution of the source image.

    scaleMode: number

    The Scale Mode the image will use when rendering. Either Linear or Nearest.

    The source of the image data.

    This is either an Image Element, a Canvas Element, a Video Element, a RenderTexture or a WebGLTextureWrapper.

    In Phaser 3.60 and above it can also be a Compressed Texture data object.

    texture: Texture

    The Texture this TextureSource instance belongs to.

    width: number

    The width of the source image. If not specified in the constructor it will check the naturalWidth, videoWidth, and then width properties of the source image.

    • Destroys this Texture Source and frees associated resources.

      In WebGL mode, the underlying WebGL texture is deleted from the GPU via the renderer. If the source is a canvas, it is returned to the CanvasPool. All internal references are then set to null.

      Returns void

    • Creates a WebGL Texture, if required, and sets the Texture filter mode.

      Parameters

      • game: Game

        A reference to the Phaser Game instance.

      Returns void

    • Sets the Filter Mode for this Texture.

      The mode can be either Linear, the default, or Nearest.

      For pixel-art you should use Nearest.

      Parameters

      Returns void

    • Sets the UNPACK_FLIP_Y_WEBGL flag for the WebGL Texture during texture upload.

      Parameters

      • Optionalvalue: boolean

        Should the WebGL Texture be flipped on the Y axis on texture upload or not? Default true.

      Returns void

    • Sets the wrap mode for this TextureSource. This is only available for WebGL.

      The wrap mode can be one of the following:

      • Phaser.Textures.WrapMode.CLAMP_TO_EDGE
      • Phaser.Textures.WrapMode.REPEAT
      • Phaser.Textures.WrapMode.MIRRORED_REPEAT

      Note that only CLAMP_TO_EDGE is supported for non-power of two textures. If another wrap mode is specified for such a texture, it will be ignored.

      Parameters

      • wrapModeS: WrapMode

        The wrap mode for the S (horizontal) axis.

      • wrapModeT: WrapMode

        The wrap mode for the T (vertical) axis.

      Returns this

      This TextureSource instance.

    • Update the underlying WebGLTexture with the current source data. This is called automatically by game systems which manage textures, such as Text or Video, or on internal data changes. You should not need to call this method manually unless you are manually updating the source data.

      Returns void

    • Updates the dimensions of this Texture Source. This is called automatically by game systems which manage textures, such as Text, which renders to a dedicated canvas that changes size.

      Parameters

      • width: number

        The new width of the source image.

      • height: number

        The new height of the source image.

      Returns void

    • Change the source data of this TextureSource. This will update the underlying WebGLTexture with the new source data.

      Note that this will not update any consumers of the texture. Frames and game objects with the Size component will automatically cache width and height on creation, so you will need to update them if you change the resolution of the texture this way.

      Parameters

      Returns void