Class SpriteStore

java.lang.Object
games.stendhal.client.sprite.SpriteStore

public class SpriteStore extends Object
A resource manager for sprites in the game. Its often quite important how and where you get your game resources from. In most cases it makes sense to have a central resource loader that goes away, gets your resources and caches them for future use.

[singleton]

  • Constructor Details

    • SpriteStore

      protected SpriteStore()
  • Method Details

    • get

      public static SpriteStore get()
      Get the single instance of this class.
      Returns:
      The single instance of this class
    • getAnimatedSprite

      public AnimatedSprite getAnimatedSprite(Sprite sprite, int x, int y, int frameCount, int width, int height, int delay)
      Create an animated sprite from a tile sprite using pixel units.
      Parameters:
      sprite - The image which contains the different frames.
      x - The base X coordinate (in pixels).
      y - The base Y coordinate (in pixels).
      frameCount - The number of frames in this animation.
      width - The tile width (in pixels).
      height - The tile height (in pixels).
      delay - The minimum delay between frames.
      Returns:
      An animated sprite.
    • getAnimatedSprite

      public AnimatedSprite getAnimatedSprite(Sprite sprite, int width, int delay)
      Get an animated sprite from a sprite. The frames are calculated automatically from the dimensions of the origin sprite. The intended frames should be in a row. Each frame will have height of the origin sprite and the specified width. The number of frames will depend on the width of the origin sprite.
      Parameters:
      sprite - Origin sprite
      width - frame width
      delay - delay between the frames
      Returns:
      animated sprite
    • getAnimatedSprite

      public AnimatedSprite getAnimatedSprite(Sprite sprite, int delay)
      Get an animated sprite from a sprite. The frames are calculated automatically from the dimensions of the origin sprite. The intended frames should be in a row. Each frame will be a square with the height of the origin. The number of frames will depend on the width of the origin sprite.
      Parameters:
      sprite - Origin sprite
      delay - delay between the frames
      Returns:
      animated sprite
    • getTiles

      public Sprite[] getTiles(Sprite sprite, int x, int y, int count, int width, int height)
      Get sprite tiles from a sprite using pixel units.
      Parameters:
      sprite - The base image.
      x - The base X coordinate (in pixels).
      y - The base Y coordinate (in pixels).
      count - The number of tiles.
      width - The tile width (in pixels).
      height - The tile height (in pixels).
      Returns:
      An array of sprites.
    • getFailsafe

      public Sprite getFailsafe()
      Get the failsafe sprite. The failsafe sprite is needed in case there are newer graphic requested in server than in client. It is ok not to return a handmade one. If we cannot reach the failsafe icon, we have bigger problems then just the need to show anything.
      Returns:
      The failsafe sprite.
    • getSprite

      public Sprite getSprite(String ref)
      Retrieve a sprite from the store.
      Parameters:
      ref - The reference to the image to use for the sprite
      Returns:
      A sprite instance containing an accelerate image of the request reference
    • getCombatSprite

      public Sprite getCombatSprite(String icon)
      Retrieve a sprite from the "combat" folder
      Parameters:
      icon - Name of pixmaps without full path
      Returns:
      A sprite instance containing an accelerate image of the request reference
    • getStatusSprite

      public Sprite getStatusSprite(String icon)
      Retrieve a sprite from the "status" folder
      Parameters:
      icon - Name of pixmaps without full path
      Returns:
      A sprite instance containing an accelerate image of the request reference
    • getColoredSprite

      public Sprite getColoredSprite(String ref, Color color)
      Get a colored version of a sprite.
      Parameters:
      ref - base sprite reference
      color - painting color
      Returns:
      base sprite colored with color
    • getModifiedSprite

      public Sprite getModifiedSprite(String baseRef, Color color, Composite blend)
      Get a modified version of a sprite.
      Parameters:
      baseRef - base sprite reference
      color - modifying color
      blend - composite mode to paint color over the original sprite
      Returns:
      base sprite colored with color
    • createModifiedRef

      public String createModifiedRef(String baseRef, Color color, Composite blend)
      Get a reference string for a modified sprite.
      Parameters:
      baseRef - reference for the base sprite
      color -
      blend -
      Returns:
      reference string
    • modifySprite

      public Sprite modifySprite(Sprite base, Color color, Composite blend, Object ref)
      Get a modified variant of a sprite. The existence of a previous instance is not checked, so this should not be called unless retrieving an existing modified sprite has failed.
      Parameters:
      base - original sprite
      color - adjustment color
      blend - blend mode for applying the adjustment color
      ref - reference for the new sprite
      Returns:
      modified sprite
    • existsSprite

      public boolean existsSprite(String ref)
      Checks if a file exists.
      Parameters:
      ref - the file name
      Returns:
      if sprite exists in store false otherwise
    • getEmptySprite

      public Sprite getEmptySprite()
      Get an empty sprite with the size of a single tile.
      Returns:
      An empty sprite.
    • getEmptySprite

      public Sprite getEmptySprite(int width, int height)
      Get an empty sprite.
      Parameters:
      width - The width.
      height - The height.
      Returns:
      An empty sprite.
    • getTile

      public Sprite getTile(Sprite sprite, int x, int y, int width, int height)
      Create a sprite tile (sub-region).
      Parameters:
      sprite -
      x -
      y -
      width - The width.
      height - The height.
      Returns:
      tile found in cache or new one created from sprite