Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (117)
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  
  Drawing game elements on the screen  (Read 827 times)
0 Members and 1 Guest are viewing this topic.
Offline williamwoles

Senior Newbie





« Posted 2010-05-26 15:12:05 »

Hey folks,

I have a question about performance of drawing elements to the screen and maybe some suggestion at the current scheme I do use to draw the components in my game screen.

I will explain from the beginning what I'm doing and if I'm doing something(or everything wrong) indicate me what is wrong.

Components Loading
- I got my game graphics stored in png images
- I'm using MediaTracker to see when some image is fully loaded
- While I'm loading graphics, I analyze the image content and convert color(255,0,255) to transparency and store them to Hashtable <String, BufferedImage>(I got different Hashtables, depending on what image category is)
At the moment I got in memory: creature graphics, character graphics, menu backgrounds, etc

Map Creation
- Map is created from a dat file which contains array of tile objects
- Map is only created after character does login
- At the moment after I create the map it's 3200x3200px (is it too big??)

Drawing on screen
- All of my components are drawn in personized JLabel(class which extends JLabel)
- When map loaded JLabel is created and in paint method of JLabel map image is drawn
- When characters are loaded, Hashtable <String, JLabel> is filled with characters and kept in memory for repaints
- When map objects are loaded JLabel is created and put in another Hashtable <String, JLabel>
- I got update function which calculates and changes the offsets and positions of elements
- After update is done I'm creating temporary render array were I put the JLabels in the order of drawing them on screen
- Repaint is done

Thanks is advance

Offline teletubo
« League of Dukes »

JGO Ninja


Medals: 48
Projects: 4
Exp: 8 years



« Reply #1 - Posted 2010-05-26 15:31:05 »

I think the biggest problem there is using JLabels to old your graphics .
You should load them directly in a BufferedImage and draw those images in a Graphics2D (of a canvas, for example) .

I know this has been advised over and over, but there it goes again : Kev Glass' Space Invaders 2d Tutorial :
http://www.cokeandcode.com/spaceinvaderstutorial

If you read only the first chapter thoroughly you'll be able to understand how to make your game run smooth as butter on Java2D .
Bottomline : forget the JLabels (and most of swing components) if you want to see your game looking like a game .

(Oh and I forgot to mention when I played your game : it took an awful lot to download, and i'm pretty sure it's because you're loading external images from  an URL. Don't do that, pack them with your game or a jar, it's way faster)

Offline williamwoles

Senior Newbie





« Reply #2 - Posted 2010-05-26 15:41:18 »

Quote from: teletubo
I think the biggest problem there is using JLabels to old your graphics .
You should load them directly in a BufferedImage and draw those images in a Graphics2D (of a canvas, for example) .

Ok, I see, then I'll need to do the implementation I had before Cheesy
But there is another question.. I still need to track the image positions in case of detection of MouseClicks right?

Quote from: teletubo
I know this has been advised over and over, but there it goes again : Kev Glass' Space Invaders 2d Tutorial :
http://www.cokeandcode.com/spaceinvaderstutorial

Thanks, going to check this right after finish working Tongue

Quote from: teletubo
(Oh and I forgot to mention when I played your game : it took an awful lot to download, and i'm pretty sure it's because you're loading external images from  an URL. Don't do that, pack them with your game or a jar, it's way faster)

I was already adviced to do that, didn't got time to test this.

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 (12 views)
2014-09-21 23:33:17

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

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

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

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

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

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

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

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

Tekkerue (51 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!