Results 1 to 7 of 7
- 09-04-2011, 09:02 AM #1
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ålleniusCurrently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".
- 09-04-2011, 09:54 AM #2
Member
- Join Date
- Jan 2011
- Posts
- 67
- Rep Power
- 0
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.
- 09-04-2011, 10:21 AM #3
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".
- 09-04-2011, 03:22 PM #4
Member
- Join Date
- Jan 2011
- Posts
- 67
- Rep Power
- 0
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.
- 09-04-2011, 04:04 PM #5
Re: Setting 441 new icons every second goes slow.
I will definitely try that out.
Seems to be a great idea.
Thanks,
AhCurrently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".
- 09-04-2011, 04:59 PM #6
- 09-04-2011, 05:40 PM #7
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,158
- Rep Power
- 5
Re: Setting 441 new icons every second goes slow.
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.Each time I press a key "Ex. W", he goes up.
Similar Threads
-
help with jtree icons
By ankit_k in forum AWT / SwingReplies: 4Last Post: 06-16-2011, 08:18 PM -
Icons, images, ....
By kovalensue in forum AWT / SwingReplies: 3Last Post: 03-18-2011, 12:29 AM -
New Posts Icons
By desertlizard in forum Suggestions & FeedbackReplies: 3Last Post: 12-06-2010, 05:00 PM -
how to compare icons
By panic in forum New To JavaReplies: 9Last Post: 05-21-2009, 08:16 AM -
is there anyone how can help me with image icons please?
By xbox_nutter in forum New To JavaReplies: 4Last Post: 03-27-2009, 10:26 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks