Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Performance Tuning / Re: 2D Game - Problems with Images (Memory & CPU) on: 2007-12-13 22:10:40
First of all: Thank you very much! It’s great to get so many responses in 24 hours. I really appreciate that and I’m happy about finding this forum.
I tried today to use the System.nanoTime and System.currenTimeMillis but obviously I’m too stupid to build a timer with it. I searched this forum and google, but I haven’t found a good instruction for it. If I use a Thread for it, nothing would be won, am I right? So can you please tell me how I build a timer with them?
The file size doesn’t matter? I believe you, but maybe you can explain to me why the whole game was lagging and shaking, when we used the high quality backgrounds? Then we decided to use a low quality background and it run a lot more fluid.
Then I tried using BufferStrategy, but I must have done something wrong. At first I used the tutorial I found at: http://gpwiki.org/index.php/Java:Tutorials:Double_Buffering
At first everything looked fine:

And then it destroyed the status panel I used:

The score and defeated enemies are blinking when they get updated for a really short moment they are displayed on the screen. Then I tried to change the level  Jpanel into a Level Canvas and tried to add it with: frame.getContentPane().add(canvas);

But then I get a grey background. Then I tried to change the paintComponent() method in paint() methods, but then I get nullpointerexception about graphics g. Sad It’s crazy… maybe it’s not necessary? Or is it that good for the performance? I have read that it’s not good to use canvas with swing?
The thing with double checking… there is no reason for doing it… only stupidity. Fixed it! Cheesy
At the moment I’m loading the image each time a shot is created. We thought about that ourselves and tried to change it. Do you know a good way to do it? Maybe a ImageLibrary class? In which all images are loaded and then you give in the level paintComponent() method:
public void paintComponent(Graphics G, BufferedImage spaceship)
Is this a good way? I started to build this class, but now I’m too tired and can’t concentrate any more. I will do it like that tomorrow and maybe it runs faster with it.

At the moment we are using BufferedImages. I read that I should use VolatileImages? But then I read, that the BufferedImages are way better in the actual versions?!?
Or do you mean the photoshop output? Cheesy That are mainly pngs, just the background is a jpg. I have run the application with -Dsun.java2d.trace=log and the output was:

Quote
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)sun.java2d.loops.Blit$GeneralMaskBlit::Blit(IntArgb, SrcOverNoEa, "Integer RGB DirectDraw")
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)s
un.java2d.loops.Blit$GeneralMaskBlit::Blit(IntArgb, SrcOverNoEa, "Integer RGB DirectDraw")
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)s
un.java2d.loops.Blit$GeneralMaskBlit::Blit(IntArgb, SrcOverNoEa, "Integer RGB DirectDraw")
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.Blit$GeneralMaskBlit::Blit(IntArgb, SrcOverNoEa, "Integer RGB DirectDraw")
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb)
sun.java2d.loops.Blit$GeneralMaskBlit::Blit(IntArgb, SrcOverNoEa, "Integer RGB DirectDraw")
sun.java2d.loops.MaskBlit::MaskBlit(IntArgb, SrcOver, IntRgb) sun.java2d.loops.DrawGlyphListAA::DrawGlyphListAA(AnyColor, SrcNoEa, IntRgb)


But I don’t unterstand it. Cheesy I will try the createCompatibleImage() tomorrow… if it’s a better way to handle the images. And  I will look how I can make them opaque. Then I let the method run with
-Dsun.java2d.opengl=True
On my main computer the cpu usage was lower  then, but on my laptop the content of the window didn’t load… Sad
Oh… and we are running Java on 1.6.
Again: Thank you very much. It’s really fun to make a game, although we are totally beginners. Maybe sometimes it will run as fast as it should… Cheesy
2  Game Development / Performance Tuning / Re: 2D Game - Problems with Images (Memory & CPU) on: 2007-12-12 21:00:47
I tried it with -Xprof, but it doesn't work properly. I get a few infos, but I couldn't really start the game witht the start button ( like I usually do). I only get a empty window. Then I tried -Xrunhprof but there I get a huge .txt File.

Xprof gives me the following output:
Quote
Flat profile of 0.21 secs (18 total ticks): main

  Interpreted + native   Method                       
 13.3%     0  +     2    sun.awt.Win32GraphicsEnvironment.initDisplay
 13.3%     0  +     2    java.util.zip.Inflater.inflateBytes
  6.7%     0  +     1    java.io.FileInputStream.open
  6.7%     0  +     1    java.io.WinNTFileSystem.canonicalizeWithPrefix0
  6.7%     0  +     1    java.io.FileInputStream.readBytes
  6.7%     0  +     1    sun.awt.windows.WDesktopProperties.init
  6.7%     0  +     1    sun.java2d.loops.GraphicsPrimitiveMgr.registerNativeLoops
  6.7%     1  +     0    java.awt.image.DataBufferByte.<init>
  6.7%     1  +     0    java.awt.image.ColorModel.getLinearRGB16TosRGB8LUT
  6.7%     1  +     0    java.util.zip.InflaterInputStream.read
  6.7%     1  +     0    java.lang.String.toLowerCase
 86.7%     4  +     9    Total interpreted

     Compiled + native   Method                       
  6.7%     1  +     0    com.sun.imageio.plugins.png.PNGImageReader.decodePaethFilter
  6.7%     1  +     0    Total compiled

         Stub + native   Method                       
  6.7%     0  +     1    java.lang.StrictMath.pow
  6.7%     0  +     1    Total stub

  Thread-local ticks:
 16.7%     3             Blocked (of total)


Flat profile of 6.45 secs (4 total ticks): Image Fetcher 0

  Interpreted + native   Method                       
100.0%     1  +     0    sun.awt.image.PNGImageDecoder.produceImage
100.0%     1  +     0    Total interpreted

  Thread-local ticks:
 75.0%     3             Blocked (of total)

I changed the timer to a java.util.Timer, but this wasn't that successful. I would say it was better with the javax.swing.Timer...

The dimensions are totally different.. a shot is about 5x10 and the background, or the level (scrolling down so it looks like the ship is moving) is really big... about 1200x600. The game is in 800x600. But we used the lowest quality for the background (jpg. photoshop 0) so it has a file size of 40 kb. At first we used a good looking background but it totally decreased the performance. The pngs (shots, enemies...) are made with photoshop. I don't know if they are made translucent. I will ask tomorrow. The only thing I know is, that they are made without background (no black or white), otherwise we would have a white outline / contour and the enemies, ships (.. and so on) wouldn't look like they are in the level. (I hope it was understandable Cheesy).
3  Game Development / Performance Tuning / 2D Game - Problems with Images (Memory & CPU) on: 2007-12-12 16:45:13
Hello guys,

we are programming our first 2D Java game and are very inecperienced in the topic performance tuning. We are not sure why the performance is so bad (probably there are too many reasons), but it's mainly about the Image Drawing. Before we used Images (png and jpg for the background) the performance was great and the game has run fast. About the game: It's a 2d space shooter like space invaders.
Because we are quite sure that the images cause the problems the following codes are limited to the drawing methods...

Loading of the Images (example class Shot):

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
public class Shot extends Elements {
    private BufferedImage[] shot = new BufferedImage[3];
    String shotName;
    File shotSound;
   
    public Shot(...) {

        File shotAnimation[] = new File[3];
       
        switch (mode) {
            case 0: shotName = "defaultshot"; width = 5; height = 5; break;
            ...
        }
       
        for(int i = 0; i < shotAnimation.length; i++) {
            shotAnimation[i] = new File (shotName + i + ".png");
        }
       
        try {
            for(int i = 0; i < shot.length; i++) {
                shot[i] = ImageIO.read(shotAnimation[i]);

            }
        }        
        catch (IOException e) {}
    }
   
// ...
   
    public void paintComponent(Graphics g) {
    if(getAlive() == true && counter < 3) {
            g.drawRect(getXc(), getYc(), width, height); // for collision, nothing to do with the images / problems
           g.drawImage(shot[counter], getXc(), getYc(), null);
            delay++;
            if(delay %15 == 0)
                counter++;
            if(counter == 3)
                counter = 0;
       }      
    }


We thought about loading all Images in another class and use them in the classes (shot, spaceship and so on...). Maybe this would be a performance push? We are not quite sure.

The class, whrere the paintComponent() is used (Level):

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public void paintComponent(Graphics g) {
    background.paintComponent(g);
        spaceship.paintComponent(g);
        boss.paintComponent(g);
       
        for(int i = 0; i < shots.size(); i++) {
            if(shots.get(i).getAlive() == true)
                shots.get(i).paintComponent(g);
        }

//...
   }


We are using Arraylists. Maybe this is slowing down the Performance? But we thought its better to use dynamic arraylists than the static Arrays.

The main Problem could be the Main class:

1  
2  
3  
4  
5  
6  
ActionListener Update = new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                repaint();
            }
        };
        new javax.swing.Timer(10, Update).start();


We have to repaint the whole panel after a few milliseconds, because otherwise the frame or the panel doesnt update and we aren't able to see the differences (moving ship, enemies, generates shots and so on). Everything is still and only updates, if the frame is minimized and again on the desktop.

Maybe there are another solutions for updating the frame / panel or loading the images (faster ones of course  Grin ). So it would be great, if anyone out there could help us, but thanks for taking the time reading all this anyway. Of course we would be grateful for hints on the net, but the whole possibilities in using 2D and Images some kind of overwhelmed us, that's why we decided to post something here.
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

TehJavaDev (16 views)
2014-08-28 18:26:30

CopyableCougar4 (25 views)
2014-08-22 19:31:30

atombrot (38 views)
2014-08-19 09:29:53

Tekkerue (34 views)
2014-08-16 06:45:27

Tekkerue (32 views)
2014-08-16 06:22:17

Tekkerue (20 views)
2014-08-16 06:20:21

Tekkerue (31 views)
2014-08-16 06:12:11

Rayexar (66 views)
2014-08-11 02:49:23

BurntPizza (44 views)
2014-08-09 21:09:32

BurntPizza (34 views)
2014-08-08 02:01: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!