Slick2d Renders ontop of itself

I have a gameserver that keeps transferring players and their positions to the clients (every half a second). The client is running Slick2d.
The problem is, it is rendering “on top” of itself, which is definitely not intended. The framerate keeps dropping, and texts gets more and more blurry.

Here’s some screenshots.
Right when the client opens:

http://billedeupload.dk/images/OEnZ.png

After like half a minute:

http://billedeupload.dk/images/fgbav.png

The render method:


    public void render(GameContainer gc, Graphics g) throws SlickException {
        // Apply the background
        g.drawImage(board.getBackground(), 0, 0);
        
        // Draw other players        
        
         for (int i = 0; i < otherPlayers.size(); i++) {
             Player newPlayer = otherPlayers.get(i);

             g.drawImage(new Image(newPlayer.getFigure()), newPlayer.getX() - 30, newPlayer.getY() - 53);
             g.setColor(Color.white);
             g.drawString(newPlayer.getName(), newPlayer.getX() - 18, newPlayer.getY() + 17);
         }
    }


I’m by no means good at this programming stuff, but aren’t you creating a new Image each frame in the render method, instead of creating the Images in your create method?

The render-method is meant to create an image, of the images you put inthere like i’ve done :slight_smile: As for that, i’m pretty sure it’s right :smiley:

Edit: The problem is, when a play is in the PlayList, it doesn’t remove the old one from the screen when he gets a new position. So every time the PlayerList is refreshed, the old one is still hanging on the image :frowning:

It’s definitely not. You’re supposed to create the Image once when you load it and then pass out references to that Image to everything that needs it. At the moment, you’re creating one image per player every frame. On top of that, you’re not deleting your Image objects once it’s no longer used. Although Java rarely requires you to manually unload/delete resources, Slick2D uses OpenGL which stores textures (= images) on the graphics cards video RAM, so it does require you to manually signal when to delete a texture.

Concerning your main problem, I’m pretty sure you’re creating more and more objects each frame, most likely when you get network update or something like that. The “blurry” text is just the same text drawn with blending over itself lots of times, so the color approaches 1.0 for all pixels in the font that aren’t completely transparent. You probably have lots of player objects too. You seem to have some pretty heavy memory leaks, so try to take care of those and the problem should fix itself.

I found the bug.
Every time the client should refresh the PlayerList, it just added the same players again :slight_smile: