I'm using the Slick2D Java game library and I want to set the scale of the graphics object that gets passed to the render method in my game loop. I'd like to do this outside the render method, so that I would only have to call the setScale() method once. I am implementing my game as StateBasedGame, so I'd to like to initialize my graphics object in my StateBasedGame class. Where would be the appropriate place to do this?


First, are you really sure to understand the concept of StateBasedGame of Slick2D? If you are not sure about it, here is a good introduction.

From here i see two potential ways to load your assets before running your game.

  1. You could do it in your StateBasedGame implementation. You just need to write a kind of loadAssets method that get called before entering any state.
  2. Create a dedicated state that will be in charge of loading your game assets. I think this is a better approach because it will allow you to implement a kind of loading screen (with a progress bar or whatever). Once you are done with loading, you can simply enter your game state which will run your game loop.

From here you may wonder how to share your assets between states? I'm not quite sure but i don't think Slick2D comes with an out of the box solution for managing assets so i think you will have to write your own.

A possible solution could be a singleton class like:

public class AssetManager extends HashMap<String, Object> {
    private static AssetManager _instance = null;

    private AssetManager() {

    public static AssetManager getManager() {
        if (_instance == null)
            _instance = new AssetManager();
        return _instance;

So you can feed it with your assets in your loading state:

AssetManager.getManager().put("asset_key", ...);

And request for a particular asset:

AssetType = (AssetType) AssetManager.getManager().get("asset_key");

I think this is the easiest way for managing your assets and if you want to improve it, you can find inspiration from the libGDX's AssetLoader.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.