Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (115)
games submitted by our members
Games in WIP (563)
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 503 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:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
    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);
         }
    }
Offline Shiu

Junior Member


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.

Myomyomyo.
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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

radar3301 (11 views)
2014-09-21 23:33:17

BurntPizza (28 views)
2014-09-21 02:42:18

BurntPizza (19 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (27 views)
2014-09-20 20:14:06

BurntPizza (29 views)
2014-09-19 03:14:18

Dwinin (47 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (102 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!