Slick2D making AppletGameContainer

Alright, so I have this game that I made a while back and now I want to put it on my website BUT the problem is I made it using AppGameContainer. I’m not quite sure how to change the AppGameContainer to an AppletGameContainer. Here’s what my main class looks like.



public class Main {

	public static void main(String[] args) {
		
		AppGameContainer game;
		
		try {
			game = new AppGameContainer(new Engine("Galactic Warrior"));
			game.setIcon("resources/images/ico3.png");
			game.setDisplayMode(640, 480, false);
			game.setMaximumLogicUpdateInterval(60);
			game.setTargetFrameRate(60);
			game.setAlwaysRender(true);
			game.setVSync(true);
			game.setShowFPS(false);
			game.start();
		} catch (SlickException e) {
			e.printStackTrace();
		}
	}

}


So how exactly would this be done? Hope you can help me, would strongly be appreciated! I’ve been stuck on this for a good while now,

You need to make a working Game first. (Like a BasicGame for example.) Then you would use the AppGameContainer as a wrapper holding the game. I’ll use your Main class like an example…


//Note the change under this line!
public class Main extends BasicGame{

    public static void main( String[] args ) {
        try{ 
            AppGameContainer app = new AppGameContainer(new Main());
            app.setDisplayMode( 640, 480, false );
            app.start();
        } catch ( SlickException e ) { 
            System.err.println(e);
        } 
    }

    //You must have a constructor that you can call within the main function.
    public Main(){
          super("Galactic Warrior");
          //The above line is necessary for this to work. Then, you may put extra initialization 
          //things here, if that is your coding style...
    }

//You are going to have to write in the init(), update(), and render() code
...
}

If done correctly, you should be able to run this as a Java application. (But you’ll need to connect all the Slick libraries correctly and the native libs correctly for this to work.)

Well I do have a working game, this was just my main class. :stuck_out_tongue: I’m just very unsure of how to make it work on a browser. Don’t I need to change my AppGameContainer to an AppletGameContainer…?

Nope, you should not need to do that at all, if your class is written exactly like this, then you’ll want to take a look at this tutorial. Especially #4 and #5 in that list. Once you put your game into a jar and follow these instructions, you should be able to get it to work into an applet.

Alright, I’ll give it a try. :slight_smile: I’ll give news if I get it working!