Search code examples
javaappletlwjglslick2d

Getting Applet Parameters from Slick2D Game


In a Slick2D game, how can I access parameters passed to the AppletGameContainer?

I've got a Slick2D game that I'd like to run both as an applet, and as a standalone application.

When the game is running as an applet, I'd like to access some information passed to it. I was thinking maybe I could do an instanceof check of the GameContainer in StateBasedGame#initGameStates, but AppletGameContainer does not inherit from GameContainer.

Is there a feature of the Slick2D framework that allows for easy access to applet parameters, or better still, some layer of abstraction that will allow access to applet parameters or command-line arguments, without my game having to know which container it was started by?


Solution

  • AppletGameContainer doesn't share the same heritage, but instead defines a public inner class, the rather ambiguously-named Container. It is an instance of this that gets passed to the StateBasedGame implementation.

    Hence the check should have been:

    container instanceof AppletGameContainer.Container
    

    ...and the code to acquire the parameters:

    ((AppletGameContainer.Container) container).getParameter("paramKey");