Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (602)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (650)
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:
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:

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
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:
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
  6.7%     0  +     1
  6.7%     0  +     1
  6.7%     0  +     1
  6.7%     0  +     1
  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
  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):

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] =[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);
            if(delay %15 == 0)
            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):

public void paintComponent(Graphics g) {
        for(int i = 0; i < shots.size(); i++) {
            if(shots.get(i).getAlive() == true)


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:

ActionListener Update = new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
        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]
Jesse (16 views)
2015-07-29 04:35:27

Riven (37 views)
2015-07-27 16:38:00

Riven (18 views)
2015-07-27 15:35:20

Riven (21 views)
2015-07-27 12:26:13

Riven (12 views)
2015-07-27 12:23:39

BurntPizza (30 views)
2015-07-25 00:14:37

BurntPizza (42 views)
2015-07-24 22:06:39

BurntPizza (24 views)
2015-07-24 06:06:53

NoxInc (31 views)
2015-07-22 22:16:53

NoxInc (20 views)
2015-07-22 22:13:39
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 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‑
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!