PokéRogue
    Preparing search index...

    A Texture consists of a source, usually an Image from the Cache, and a collection of Frames. The Frames represent the different areas of the Texture. For example a texture atlas may have many Frames, one for each element within the atlas. Where-as a single image would have just one frame, that encompasses the whole image.

    Every Texture, no matter where it comes from, always has at least 1 frame called the __BASE frame. This frame represents the entirety of the source image.

    Textures are managed by the global TextureManager. This is a singleton class that is responsible for creating and delivering Textures and their corresponding Frames to Game Objects.

    Sprites and other Game Objects get the texture data they need from the TextureManager.

    Hierarchy (View Summary)

    Index
    customData: object

    Any additional data that was set in the source JSON (if any), or any extra data you'd like to store relating to this texture.

    dataSource: any[]

    An array of TextureSource data instances. Used to store additional data images, such as normal maps or specular maps.

    firstFrame: string

    The name of the first frame of the Texture.

    frames: object

    A key-value object pair associating the unique Frame keys with the Frames objects.

    frameTotal: number

    The total number of Frames in this Texture, including the __BASE frame.

    A Texture will always contain at least 1 frame because every Texture contains a __BASE frame by default, in addition to any extra frames that have been added to it, such as when parsing a Sprite Sheet or Texture Atlas.

    key: string

    The unique string-based key of this Texture.

    A reference to the Texture Manager this Texture belongs to.

    smoothPixelArt: boolean | null

    Controls whether shaders using this texture should apply smooth interpolation when rendering pixel art. When enabled, the renderer uses shader-based smoothing to reduce the jagged appearance of upscaled pixel art. This relies on shader support.

    If null, the game default will be used.

    source: TextureSource[]

    An array of TextureSource instances. These are unique to this Texture and contain the actual Image (or Canvas) data.

    • Adds a new Frame to this Texture.

      A Frame is a rectangular region of a TextureSource with a unique index or string-based key.

      The name given must be unique within this Texture. If it already exists, this method will return null.

      Parameters

      • name: string | number

        The name of this Frame. The name is unique within the Texture.

      • sourceIndex: number

        The index of the TextureSource that this Frame is a part of.

      • x: number

        The x coordinate of the top-left of this Frame.

      • y: number

        The y coordinate of the top-left of this Frame.

      • width: number

        The width of this Frame.

      • height: number

        The height of this Frame.

      Returns Frame | null

      The Frame that was added to this Texture, or null if the given name already exists.

    • Destroys this Texture and releases references to its sources and frames.

      Returns void

    • Gets a Frame from this Texture based on either the key or the index of the Frame.

      In a Texture Atlas Frames are typically referenced by a key. In a Sprite Sheet Frames are referenced by an index. Passing no value for the name returns the base texture.

      Parameters

      • Optionalname: string | number

        The string-based name, or integer based index, of the Frame to get from this Texture.

      Returns Frame

      The Texture Frame.

    • Given a Frame name, return the data source image it uses to render with. You can use this to get the normal map for an image for example.

      This will return the actual DOM Image.

      Parameters

      • Optionalname: string | number

        The string-based name, or integer based index, of the Frame to get from this Texture.

      Returns HTMLCanvasElement | HTMLImageElement

      The DOM Image or Canvas Element.

    • Based on the given Texture Source Index, this method will get all of the Frames using that source and then work out the bounds that they encompass, returning them in an object.

      This is useful if this Texture is, for example, a sprite sheet within an Atlas, and you need to know the total bounds of the sprite sheet.

      Parameters

      • OptionalsourceIndex: number

        The index of the TextureSource to get the Frame bounds from. Default 0.

      Returns RectangleLike

      An object containing the bounds of the Frames using the given Texture Source Index.

    • Returns an array with all of the names of the Frames in this Texture.

      Useful if you want to randomly assign a Frame to a Game Object, as you can pick a random element from the returned array.

      Parameters

      • OptionalincludeBase: boolean

        Include the __BASE Frame in the output array? Default false.

      Returns string[]

      An array of all Frame names in this Texture.

    • Returns an array of all the Frames in the given TextureSource.

      Parameters

      • sourceIndex: number

        The index of the TextureSource to get the Frames from.

      • OptionalincludeBase: boolean

        Include the __BASE Frame in the output array? Default false.

      Returns Frame[]

      An array of Texture Frames.

    • Given a Frame name, return the source image it uses to render with.

      This will return the actual DOM Image or Canvas element.

      Parameters

      • Optionalname: string | number

        The string-based name, or integer based index, of the Frame to get from this Texture.

      Returns HTMLCanvasElement | HTMLImageElement | RenderTexture

      The DOM Image, Canvas Element or Render Texture.

    • Takes the given TextureSource and returns the index of it within this Texture. If it's not in this Texture, it returns -1. Unless this Texture has multiple TextureSources, such as with a multi-atlas, this method will always return zero or -1.

      Parameters

      Returns number

      The index of the TextureSource within this Texture, or -1 if not in this Texture.

    • Checks to see if a Frame matching the given key exists within this Texture.

      Parameters

      • name: string

        The key of the Frame to check for.

      Returns boolean

      True if a Frame with the matching key exists in this Texture.

    • Removes the given Frame from this Texture. The Frame is destroyed immediately.

      Any Game Objects using this Frame should stop using it before you remove it, as it does not happen automatically.

      Parameters

      • name: string

        The key of the Frame to remove.

      Returns boolean

      True if a Frame with the matching key was removed from this Texture.

    • Adds a data source image to this Texture.

      An example of a data source image would be a normal map, where all of the Frames for this Texture equally apply to the normal map.

      There can only be one data source per 'regular' source entry.

      Parameters

      • data: TextureSource | TextureSource[]

        The source image data.

      • OptionalstartIndex: number

        The index of the first source to update. If there are multiple data elements, they will be applied to subsequent indices. Default 0.

      • Optionalrenew: boolean

        Whether to destroy the existing source and create a new one, if a source is already in the array at an index. Default false.

      • Optionalwidth: number

        Width to use, if not available from the data (e.g. using a Uint8Array)

      • Optionalheight: number

        Height to use, if not available from the data (e.g. using a Uint8Array)

      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.

      The mode applies to the entire Texture, not just a specific Frame of it.

      Parameters

      Returns void

    • Set the smoothPixelArt property for this Texture. If true, it will also run setFilter(Phaser.Textures.FilterMode.LINEAR) to enable the necessary linear filtering. If false, it will not change the filter mode, as it doesn't know the previous state, nor is it necessary to change it.

      Parameters

      • value: boolean | null

        Set to true to enable smooth pixel art interpolation and apply LINEAR filtering. Set to false to disable smooth interpolation without changing the filter mode. Set to null to use the game's default setting.

      Returns void

    • Set the source data for this Texture. By default, this will update any existing sources, effectively overwriting them.

      It's advisable to only swap between textures of the same size, as the dimensions of game objects are often derived from texture size and might change in unexpected ways if they don't match.

      Any related dataSource members must be updated. See Phaser.Textures.Texture#setDataSource.

      Parameters

      • data: TextureSource | TextureSource[] | TextureSource | TextureSource[]

        The source image data.

      • OptionalstartIndex: number

        The index of the first source to update. If there are multiple data elements, they will be applied to subsequent indices. Default 0.

      • Optionalrenew: boolean

        Whether to destroy the existing source and create a new one, if a source is already in the array at an index. Default false.

      • Optionalwidth: number

        Width to use, if not available from the data (e.g. using a Uint8Array)

      • Optionalheight: number

        Height to use, if not available from the data (e.g. using a Uint8Array)

      Returns void

    • Set the wrap mode for this Texture.

      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.

      • OptionalwrapModeT: WrapMode

        The wrap mode for the T (vertical) axis.

      Returns void