Sign in to follow this  
minibutmany

Slick2D on a JPanel

Recommended Posts

Hi,

I'm working on a 2D platform game. I was foolish and used java2d graphics, but now that I face some slight performance issues I want to move over to Slick instead. The way that I have it set up is a JPanel on it's own thread is constantly updating graphics while the JFrame that it sits upon handles keypresses, and has the main game loop. I only want to re-write the rendering class for slick, but keep the rest of my code the same. How do I get slick to act like java 2d and paint to a JPanel?

Would It be easier to just reformat my whole project to work with Slick windows?

Edited by minibutmany

Share this post


Link to post
Share on other sites

Slick does provide a render, update and init method in the BasicGame class. In the render method there is two given parameters (GameContainer gc, Graphics g). The Graphics object seems to provides similar drawing method as java2d graphics. I beleive you can adapt easily your rendering class to use Slick 2D engine with that Graphics.

Here's an example of how to draw a rectangle in the Slick2D engine :

 

public void render(GameContainer gc, Graphics g) throws SlickException {
        g.drawRect(0,0,20,20);
    }

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this