Class Spritesheets


public final class Spritesheets

Manages the loading, storing, and retrieval of spritesheets.

This class provides methods to load spritesheets from various sources, manage custom keyframe durations, and handle listeners for resource container clearing events.

  • Method Details

    • add

      public void add(String name, Spritesheet spritesheet)
      Adds a spritesheet to the collection of loaded spritesheets.
      Parameters:
      name - The name of the spritesheet.
      spritesheet - The spritesheet to add.
    • addClearedListener

      public void addClearedListener(ResourcesContainerClearedListener listener)
      Adds a listener for resource container clearing events.
      Parameters:
      listener - The listener to add.
    • removeClearedListener

      public void removeClearedListener(ResourcesContainerClearedListener listener)
      Removes a listener for resource container clearing events.
      Parameters:
      listener - The listener to remove.
    • clear

      public void clear()
      Clears all loaded spritesheets and notifies listeners of the clearing event.
    • contains

      public boolean contains(String name)
      Checks if a spritesheet with the specified name is loaded.
      Parameters:
      name - The name of the spritesheet.
      Returns:
      True if the spritesheet is loaded, false otherwise.
    • get

      public Spritesheet get(String path)
      Finds Spritesheets that were previously loaded by any load method or by the sprites.info file.
      Parameters:
      path - The path of the spritesheet.
      Returns:
      The Spritesheet associated with the path or null if not loaded yet
    • get

      public Collection<Spritesheet> get(Predicate<? super Spritesheet> pred)
      Gets a collection of spritesheets that match the specified predicate.
      Parameters:
      pred - The predicate to filter the spritesheets.
      Returns:
      A collection of spritesheets that match the predicate, or an empty collection if the predicate is null.
    • getAll

      public Collection<Spritesheet> getAll()
      Gets a collection of all loaded spritesheets.
      Returns:
      A collection of all loaded spritesheets.
    • getCustomKeyFrameDurations

      public int[] getCustomKeyFrameDurations(String name)
      Gets the custom keyframe durations for the specified spritesheet name.
      Parameters:
      name - The name of the spritesheet.
      Returns:
      An array of custom keyframe durations, or an empty array if none are found.
    • getCustomKeyFrameDurations

      public int[] getCustomKeyFrameDurations(Spritesheet sprite)
      Gets the custom keyframe durations for the specified spritesheet.
      Parameters:
      sprite - The spritesheet to get the custom keyframe durations for.
      Returns:
      An array of custom keyframe durations, or an empty array if none are found.
    • load

      public Spritesheet load(BufferedImage image, String path, int spriteWidth, int spriteHeight)
      Loads a spritesheet from the specified image, path, width, and height.
      Parameters:
      image - The image of the spritesheet.
      path - The path of the spritesheet.
      spriteWidth - The width of each sprite in the spritesheet.
      spriteHeight - The height of each sprite in the spritesheet.
      Returns:
      The loaded spritesheet.
    • load

      public Spritesheet load(ITileset tileset)
      Loads a spritesheet from the specified tileset.
      Parameters:
      tileset - The tileset to load the spritesheet from.
      Returns:
      The loaded spritesheet, or null if the tileset or its image is null, or if the image's absolute source path is null.
    • load

      public Spritesheet load(SpritesheetResource info)
      Loads a spritesheet from the specified spritesheet resource.
      Parameters:
      info - The spritesheet resource containing the information to load the spritesheet.
      Returns:
      The loaded spritesheet, or null if the image is null or empty.
    • loadFrom

      public List<Spritesheet> loadFrom(String spriteInfoFile)
      The sprite info file must be located under the GameInfo#getSpritesDirectory() directory.
      Parameters:
      spriteInfoFile - The path to the sprite info file.
      Returns:
      A list of spritesheets that were loaded from the info file.
    • saveTo

      public boolean saveTo(String spriteInfoFile, boolean metadataOnly)
      Saves the spritesheet information to the specified file.
      Parameters:
      spriteInfoFile - The path to the file where the spritesheet information will be saved.
      metadataOnly - If true, only the metadata will be saved; if false, both the sprites and metadata will be saved.
      Returns:
      True if the spritesheet information was successfully saved, false otherwise.
    • load

      public Spritesheet load(String path, int spriteWidth, int spriteHeight)
      Loads a spritesheet from the specified path, width, and height.
      Parameters:
      path - The path of the spritesheet.
      spriteWidth - The width of each sprite in the spritesheet.
      spriteHeight - The height of each sprite in the spritesheet.
      Returns:
      The loaded spritesheet.
    • remove

      public Spritesheet remove(String path)
      Removes a spritesheet from the collection of loaded spritesheets.
      Parameters:
      path - The path of the spritesheet to remove.
      Returns:
      The removed spritesheet, or null if no spritesheet was found for the specified path.
    • update

      public Spritesheet update(SpritesheetResource info)
      Updates a spritesheet with the specified resource information.
      Parameters:
      info - The resource information for the spritesheet to update.
      Returns:
      The updated spritesheet, or null if the resource information is invalid or the spritesheet could not be updated.