Results 1 to 7 of 7
  1. #1
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    3

    Default Setting 441 new icons every second goes slow.

    Ohai! I'm working on a 2D side-scroller as my main project,
    the goal for this is to get an awsome game that people likes to play.

    The grid is basicly (As I said a couple of weeks ago) a lot of JPanels + JLabels together.
    JLabel onto JPanel.

    Each time I press a key "Ex. W", he goes up. Well, the JLabels just gets refreshed
    from an integer array which is 1000 x 1000. It checks what the next numbers in the array is &
    it changed the image to an image into my image array.

    "But here is the problem": It goes to slow to change those 441 JLabels every time you press a button.
    It feels like one I am playing on a very old PC. Any ideas to get better performance to it?

    Kind,
    Regards Alexander Hållenius
    Currently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".

  2. #2
    Skiller is offline Member
    Join Date
    Jan 2011
    Posts
    67
    Rep Power
    0

    Default

    If you've got the time and patience to learn it, OpenGL is many orders of magnitude faster at drawing than any Java UI classes as it can leverage the GPU, even on low end graphics hardware the difference is huge when you do things right. I believe the Java implementation is done through JOGL. However it does take a while to learn and even longer before you can really start using it well, though if you stick to 2D it's not too bad.
    If you are interested in learning OpenGL there are some good tutorials at NeHe Productions - Everything OpenGL they are for C++ but the languages are similar enough that you should be able to understand and apply the tutorials to Java, though you'll need to read the JOGL docs on how to set up the window as the way NeHe does it is specific to windows and C++.

    Of course it may just be you are using the JLabels inefficiently and you don't actually need OpenGL, how exactly are you changing the JLabels? And which JLabels are you changing? 441 sounds like you are changing more than you need to, you should probably only need to be changing JLabels as they wrap around the screen or if the data the JLabel represents changes while the JLabel is visible, at least that's the way I'd be doing it if I didn't use OpenGL.
    Currently developing Cave Dwellers, a Dwarf Fortress/Minecraft style game for Android.

  3. #3
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    3

    Default

    I'm changing the JLabels /w the .setIcon();

    Why do I need to change them?
    I suppose it's the easyest way for side-scrolling in Java, at least for a Dwarf Fortress looking game 2D. Seen from above.
    Currently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".

  4. #4
    Skiller is offline Member
    Join Date
    Jan 2011
    Posts
    67
    Rep Power
    0

    Default Re: Setting 441 new icons every second goes slow.

    It may be faster to move the visible JLables rather than changing the images they use. Most UI solutions for applications cache their pixel data and only redraw it if it's invalidated as the drawing of the pixel data is usually fairly slow, the setIcon method will almost certainly invalidate the pixel data requiring it to be re-drawn, however changing the position of the JLabels probably won't which could speed things up a fair bit. Of course it makes things a little more difficult as you have to then wrap the JLables that would go off screen to the other side instead and you still need to update those, but it could speed up the drawing.

    However I should advise you that I'm not familiar with JLabels or any of the Java UI stuff as I find it easier (and far better for performance) to write my own UIs than learn how to use another, so I'm mostly guessing at the internal workings of JLabels based on my experience with how other UIs I've had to work with operated. But if you have the time it's something that might be worth trying.
    Currently developing Cave Dwellers, a Dwarf Fortress/Minecraft style game for Android.

  5. #5
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    3

    Default Re: Setting 441 new icons every second goes slow.

    I will definitely try that out.
    Seems to be a great idea.

    Thanks,
    Ah
    Currently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Setting 441 new icons every second goes slow.

    Quote Originally Posted by Alerhau View Post
    I'm changing the JLabels /w the .setIcon();
    Are you caching the Icons or constructing new Icons each time?

    db

  7. #7
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,226
    Rep Power
    6

    Default Re: Setting 441 new icons every second goes slow.

    Each time I press a key "Ex. W", he goes up.
    Not sure why change 441 icons every time. Maybe instead your main panel should be added to a scrollpane (without any scrollbars). Then instead of changing all the icons, you scroll the panel down. This is done by using the scrollRectToVisible() method or you could use the setViewPosition() method of the JViewport of the scroll pane.

Similar Threads

  1. help with jtree icons
    By ankit_k in forum AWT / Swing
    Replies: 4
    Last Post: 06-16-2011, 08:18 PM
  2. Icons, images, ....
    By kovalensue in forum AWT / Swing
    Replies: 3
    Last Post: 03-18-2011, 12:29 AM
  3. New Posts Icons
    By desertlizard in forum Suggestions & Feedback
    Replies: 3
    Last Post: 12-06-2010, 05:00 PM
  4. how to compare icons
    By panic in forum New To Java
    Replies: 9
    Last Post: 05-21-2009, 08:16 AM
  5. is there anyone how can help me with image icons please?
    By xbox_nutter in forum New To Java
    Replies: 4
    Last Post: 03-27-2009, 10:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •