Class SpriteAtlas

java.lang.Object
nl.colorize.multimedialib.stage.SpriteAtlas

public class SpriteAtlas extends Object
Packs a number of images into a larger image, with each image existing as a named region. Using a sprite atlas generally provides better performance for both loading and rendering images.

Although a sprite atlas is usually expected to consist of one large image, this is not a hard requirement. This class allows the atlas to spread its sub-images across multiple atlases, while still providing central access to all sub-images across all atlas images.

  • Constructor Details

    • SpriteAtlas

      public SpriteAtlas()
  • Method Details

    • add

      public void add(String name, Image atlas, Region region)
    • get

      public Image get(String name)
      Returns the sub-image with the specified name. If the same sub-image is requested multiple times, the image data will be cached and returned on subsequent requests.
      Throws:
      NoSuchElementException - if the sprite atlas does not contain a sub-image with that name.
    • get

      public List<Image> get(List<String> names)
      Returns a list of sub-images that match the requested names. This is a bulk version of get(String).
    • get

      public List<Image> get(Predicate<String> filter)
      Returns all sub-images that match the predicate. The sub-images will be returned in alphabetical order based on their name.
    • getAll

      public List<Image> getAll()
      Returns all sub-images in this sprite atlas. The sub-images will be returned in alphabetical order based on their name.
    • contains

      public boolean contains(String name)
    • merge

      public SpriteAtlas merge(SpriteAtlas other)
      Creates a new sprite atlas that includes all sub-images from both this atlas and the provided other atlas. Each sprite atlas can span multiple images, as explained in the class documentation, so the combined sprite atlas is transparent to the user.
      Throws:
      IllegalArgumentException - If the two atlases do not include sub-images with the same name.