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 Summary
Modifier and TypeMethodDescriptionvoidadd(String name, Spritesheet spritesheet) Adds a spritesheet to the collection of loaded spritesheets.voidAdds a listener for resource container clearing events.voidclear()Clears all loaded spritesheets and notifies listeners of the clearing event.booleanChecks if a spritesheet with the specified name is loaded.Finds Spritesheets that were previously loaded by any load method or by the sprites.info file.get(Predicate<? super Spritesheet> pred) Gets a collection of spritesheets that match the specified predicate.getAll()Gets a collection of all loaded spritesheets.int[]Gets the custom keyframe durations for the specified spritesheet.int[]Gets the custom keyframe durations for the specified spritesheet name.Loads a spritesheet from the specified tileset.load(SpritesheetResource info) Loads a spritesheet from the specified spritesheet resource.load(BufferedImage image, String path, int spriteWidth, int spriteHeight) Loads a spritesheet from the specified image, path, width, and height.Loads a spritesheet from the specified path, width, and height.The sprite info file must be located under the GameInfo#getSpritesDirectory() directory.Removes a spritesheet from the collection of loaded spritesheets.voidRemoves a listener for resource container clearing events.booleanSaves the spritesheet information to the specified file.update(SpritesheetResource info) Updates a spritesheet with the specified resource information.
-
Method Details
-
add
Adds a spritesheet to the collection of loaded spritesheets.- Parameters:
name- The name of the spritesheet.spritesheet- The spritesheet to add.
-
addClearedListener
Adds a listener for resource container clearing events.- Parameters:
listener- The listener to add.
-
removeClearedListener
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
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
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
Spritesheetassociated with the path or null if not loaded yet
-
get
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
Gets a collection of all loaded spritesheets.- Returns:
- A collection of all loaded spritesheets.
-
getCustomKeyFrameDurations
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
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
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
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
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
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
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
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
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
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.
-