vooga.engine.resource
Class Resources

java.lang.Object
  extended by vooga.engine.resource.Resources

public class Resources
extends java.lang.Object

The Resources class stores references to various resources which can be accessed from anywhere in the game. The available types of resources include BufferedImage Arrays, Sounds, Strings, Integers, and Doubles.
All of the available resources can be loaded on a one-at-a-time basis by passing in a String filepath or by passing in a File.
Resources also has the ability to load multiple resources at once using an XML file. This is the main utility of the Resources class.
The vooga.engine.core.Game class calls the Resources.loadResourcesXMLFile method on the file "resources.xml". Each game should have a resources.xml file located in their resources package. Further resources can be added later using any load method.
Images are stored as BufferedImage arrays. In the case of images which are not animations, the array only has one element. Images can be retrieved as animations, but the animation will only have one frame. Likewise, animations can be retrieved as images and only the first frame will be retrieved. Images are loaded using the Game.loadImage() method and supports png, gif, bmp, and jpg files.
Example files following the standard XML format can be found in the examples.resources package.


Constructor Summary
Resources()
           
 
Method Summary
static java.awt.image.BufferedImage[] getAnimation(java.lang.String key)
          Returns the BufferedImage[] associated with the given label.
static java.lang.String getDefaultPath()
          Returns the default path of this Resources.
static double getDouble(java.lang.String key)
          Returns the double associated with the given double label.
static Game getGame()
          Gets the game currently using Resources.
static java.awt.image.BufferedImage getImage(java.lang.String key)
          Returns the BufferedImage associated with the given label.
static int getInt(java.lang.String key)
          Returns the int associated with the given int label.
static java.lang.String getSound(java.lang.String key)
          Returns the String associated with the given Sound label.
static java.lang.String getString(java.lang.String key)
          Returns the String associated with the given String label.
static java.awt.image.BufferedImage[] getVisual(java.lang.String key)
          Returns the BufferedImage[] associated with the given label.
static void initialize(Game game)
          Sets the Game of this Resources and sets the default path to be a blank string.
static void initialize(Game game, java.lang.String defaultFilePath)
          Sets the game of this Resources and sets the default path.
static void loadAnimation(java.lang.String key, java.io.File[] files)
          Puts a new entry into this Resources's imageMap, with a String key and a BufferedImage[] value.
static void loadAnimation(java.lang.String key, java.lang.String[] filePaths)
          Puts a new entry into this Resources's imageMap, with a String key and a BufferedImage[] value.
static void loadDouble(java.lang.String key, double doubleToLoad)
          Puts a new entry into this Resources's doubleMap, with a String key and a double value.
static void loadImage(java.lang.String key, java.io.File file)
          Puts a new entry into this Resources's imageMap, with a String key and a BufferedImage[] value.
static void loadImage(java.lang.String key, java.lang.String filePath)
          Puts a new entry into this Resources's imageMap, with a String key and a BufferedImage[] value.
static void loadInt(java.lang.String key, int intToLoad)
          Puts a new entry into this Resources's integerMap, with a String key and an int value.
static java.util.ResourceBundle loadPreLaunchData(java.lang.String filePath)
          Get data to launch the game frame from the main() method of game.
static void loadResourcesXMLFile(java.lang.String resourcesXMLFilepath)
          Reads the resources.xml file and initializes the Resources's mappings.
static void loadSound(java.lang.String key, java.io.File file)
          Puts a new entry into this Resources's soundMap, with a String key and a String value.
static void loadSound(java.lang.String key, java.lang.String filePath)
          Puts a new entry into this Resources's soundMap, with a String key and a String value.
static void loadString(java.lang.String key, java.lang.String stringToLoad)
          Puts a new entry into this Resources's stringMap, with a String key and a String value.
static void setDefaultPath(java.lang.String path)
          Changes the default path of this Resources.
static void setGame(Game game)
          Changes the Game of this Resources.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Resources

public Resources()
Method Detail

initialize

public static void initialize(Game game)
Sets the Game of this Resources and sets the default path to be a blank string.


initialize

public static void initialize(Game game,
                              java.lang.String defaultFilePath)
Sets the game of this Resources and sets the default path.


setGame

public static void setGame(Game game)
Changes the Game of this Resources.


getGame

public static Game getGame()
Gets the game currently using Resources. Allows static access to a pointer to the current game. Maybe it's bad practice but everything requires a reference to the top level entity to function properly and I'm tired of passing

Returns:

setDefaultPath

public static void setDefaultPath(java.lang.String path)
Changes the default path of this Resources.


getDefaultPath

public static java.lang.String getDefaultPath()
Returns the default path of this Resources.


loadImage

public static void loadImage(java.lang.String key,
                             java.io.File file)
Puts a new entry into this Resources's imageMap, with a String key and a BufferedImage[] value. This method is used when a single image is being put into the map.


loadImage

public static void loadImage(java.lang.String key,
                             java.lang.String filePath)
Puts a new entry into this Resources's imageMap, with a String key and a BufferedImage[] value. This method is used when a single image is being put into the map.


getImage

public static java.awt.image.BufferedImage getImage(java.lang.String key)
Returns the BufferedImage associated with the given label.


loadAnimation

public static void loadAnimation(java.lang.String key,
                                 java.io.File[] files)
Puts a new entry into this Resources's imageMap, with a String key and a BufferedImage[] value. This method is used when multiple images are being put into the map as an animation.


loadAnimation

public static void loadAnimation(java.lang.String key,
                                 java.lang.String[] filePaths)
Puts a new entry into this Resources's imageMap, with a String key and a BufferedImage[] value. This method is used when multiple images are being put into the map as an animation.


getAnimation

public static java.awt.image.BufferedImage[] getAnimation(java.lang.String key)
Returns the BufferedImage[] associated with the given label.


getVisual

public static java.awt.image.BufferedImage[] getVisual(java.lang.String key)
Returns the BufferedImage[] associated with the given label.


loadSound

public static void loadSound(java.lang.String key,
                             java.io.File file)
Puts a new entry into this Resources's soundMap, with a String key and a String value.


loadSound

public static void loadSound(java.lang.String key,
                             java.lang.String filePath)
Puts a new entry into this Resources's soundMap, with a String key and a String value.


getSound

public static java.lang.String getSound(java.lang.String key)
Returns the String associated with the given Sound label.


loadString

public static void loadString(java.lang.String key,
                              java.lang.String stringToLoad)
Puts a new entry into this Resources's stringMap, with a String key and a String value.


getString

public static java.lang.String getString(java.lang.String key)
Returns the String associated with the given String label.


loadInt

public static void loadInt(java.lang.String key,
                           int intToLoad)
Puts a new entry into this Resources's integerMap, with a String key and an int value.


getInt

public static int getInt(java.lang.String key)
Returns the int associated with the given int label.


loadDouble

public static void loadDouble(java.lang.String key,
                              double doubleToLoad)
Puts a new entry into this Resources's doubleMap, with a String key and a double value.


getDouble

public static double getDouble(java.lang.String key)
Returns the double associated with the given double label.


loadResourcesXMLFile

public static void loadResourcesXMLFile(java.lang.String resourcesXMLFilepath)
                                 throws java.io.IOException
Reads the resources.xml file and initializes the Resources's mappings. Thanks to Lucas Best, Ben Getson, and Sam Kitange for XML parsing methods.

Throws:
java.io.IOException

loadPreLaunchData

public static java.util.ResourceBundle loadPreLaunchData(java.lang.String filePath)
Get data to launch the game frame from the main() method of game. The file should be named config.properties and contain the width, height, and whether or not the game should be full screen.

Parameters:
filePath - file path to config.properties
Returns:
ResourceBundle containing necessary data for game launch