Resource Loading

From Slick2D Wiki
Jump to: navigation, search

When referencing resources (images, spritesheets, fonts, sounds etc.) the underlying class will use the ResourceManager to find the resource and obtain an input stream to it.

The resource manager first tries to look the resource up using the classpath. Putting your resources in the classpath is generally the best way to work since it makes transitioning to deployment (webstart and/or applets) much easier - since the classpath is present at testing and at deployment. Note that the context class loader is used which ensure that at deployment what ever the framework being used for deployment is can specify an appropriate class loader to obtain resources.

If the resource manager is unable to locate the resoruce within the classpath it will attempt to use the reference provided as a file name relative to the current directory. This is sometimes useful during testing. It is also possible to deploy while still being dependent on direct file reference (maybe using an installer and keeping files unjarred) but this is not recommended.

Finally if the resource manager can not locate the resource it will report an error which may stop initialisation. It is possible that resource location can fail but still the resource can remain valid and so a resource simply not being located is not always a reason to stop init.

See Also[edit]