Slick2D on a JPanel

Started by
0 comments, last by PsychotikRabbit 11 years, 4 months ago

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?

Stay gold, Pony Boy.
Advertisement

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);
    }

This topic is closed to new replies.

Advertisement