Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Slick2d Renders ontop of itself  (Read 1398 times)
0 Members and 1 Guest are viewing this topic.
Offline Reck

Senior Newbie

« Posted 2012-12-03 13:34:56 »

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:

After like half a minute:

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.drawString(newPlayer.getName(), newPlayer.getX() - 18, newPlayer.getY() + 17);
Offline Shiu

Junior Devvie

Medals: 2

« Reply #1 - Posted 2012-12-03 14:09:32 »

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?
Offline Reck

Senior Newbie

« Reply #2 - Posted 2012-12-03 14:10:43 »

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

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 :-(
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd
« Reply #3 - Posted 2012-12-03 14:19:17 »

The render-thread is meant to create an image, of the images you put inthere like i've done :-) As for that, i'm pretty sure it's right :-D
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.

Offline Reck

Senior Newbie

« Reply #4 - Posted 2012-12-03 14:27:02 »

I found the bug.
Every time the client should refresh the PlayerList, it just added the same players again :-)
Pages: [1]
  ignore  |  Print  

EgonOlsen (77 views)
2018-06-10 19:43:48

EgonOlsen (57 views)
2018-06-10 19:43:44

EgonOlsen (77 views)
2018-06-10 19:43:20

DesertCoockie (259 views)
2018-05-13 18:23:11

nelsongames (157 views)
2018-04-24 18:15:36

nelsongames (156 views)
2018-04-24 18:14:32

ivj94 (897 views)
2018-03-24 14:47:39

ivj94 (161 views)
2018-03-24 14:46:31

ivj94 (810 views)
2018-03-24 14:43:53

Solater (174 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!