Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TextureStore

Provides simple API for retrieving texture by name, by a segment of a texture or by a tile in a tileset.

The goal is to have a centralized source of textures that can be easily accessed just by a string. Simplifies serialization among other things.

To use this, a texture first has to be registered with a name, then you can access it by one of the many ways. A tileset can also be registered in which case its tiles can be retrieved via getTile().

Note: TextureStore never creates new BaseTextures. What it means is that for the purpose of performance, all the textures created from the same base texture are still part of that base texture, part of the same texture atlas.

Hierarchy

  • TextureStore

Index

Constructors

constructor

  • Creates a new Texture Factory.

    throws

    {Error} Thrown when separator's length is different than 1 character.

    Parameters

    • Default value separator: string = "/"

      Used to delimit properties of a texture rectangle

    Returns TextureStore

Accessors

separator

  • get separator(): string
  • Separator used to delimit properties of a dynamic texture rectangle

    Returns string

Methods

getTexture

  • getTexture(name: string): Texture
  • Retrieves a texture by name, where the name can be either a base name of a texture or one with the additional properties, as generated by getTextureRectangle() or getTile(). If a name with properties is passed and that texture was not previously generated in this factory it'll work exactly the same as if calling getTextureRectangle() with the basename and rectangle extracted.

    throws

    {Error} Thrown when texture for the given name was not found and did not have the valid number of properties.

    throws

    {Error} Thrown when the width or height in the texture name's properties is less than 1

    Parameters

    • name: string

      Name of the texture to retrieve

    Returns Texture

    The texture for the name

getTextureName

  • getTextureName(texture: Texture): string
  • Given a texture previously extracted from this factory returns its name. Most useful to get the generated name of textures from getTile() or getTextureRectangle().

    throws

    {Error} Thrown when texture was not previously registered nor generated.

    Parameters

    • texture: Texture

      Texture which name to get

    Returns string

    Name of the texture

getTextureRectangle

  • getTextureRectangle(name: string, x: number, y: number, width: number, height: number): Texture
  • Retrieves a rectangle from a previously registered texture or a valid texture rectangle. If the name provided is a texture rectangle, the position provided will be relative to that rectangle's frame, not the base texture's frame.

    throws

    {Error} Thrown when either width or height is less than 1

    Parameters

    • name: string

      Name of the texture to use as a basis

    • x: number

      Offset X position from the top-left corner of the texture's frame

    • y: number

      Offset Y position from the top-left corner of the texture's frame

    • width: number

      Width of the new texture

    • height: number

      Height of the new texture

    Returns Texture

    The new texture that matches the specified frame.

getTile

  • getTile(name: string, x: number, y: number): Texture
  • Retrieves a texture that matches a tile at the given position in the tileset.

    throws

    {Error} Thrown when the name of the texture was not registered as a tileset.

    Parameters

    • name: string

      Name of the tileset to use.

    • x: number

      X position of the tile

    • y: number

      Y position of the tile

    Returns Texture

    The texture for the requested tile

registerTexture

  • registerTexture(texture: Texture, name: string): void
  • Registers a texture for use in the factory.

    throws

    {Error} Thrown when texture name contains the separator provided in the constructor.

    Parameters

    • texture: Texture

      Texture to register

    • name: string

      Name of the texture to use for access

    Returns void

registerTileset

  • Registers a previously registered texture as a tileset, to allow using it with getTile() method. The texture can still be used the same way it was used previously.

    throwns

    {Error} Thrown when you try to register tileset for textureName that was not previously registered.

    throwns

    {Error} Thrown when you try to register tileset for textureName that was already registered as tileset.

    Parameters

    • textureName: string

      Name of the texture to use as the basis for the tileset

    • config: TilesetTextureConfig

      Tileset configuration

    Returns void

Generated using TypeDoc