Question

When I run my program from eclipse, it runs fine with very little load on the CPU. JProfiler (watching the program run from eclipse) says most is taken up by collision detection and drawing. When JProfiler is watching the compiled jar run, 97% of it's cpu use comes from drawImage. It's running around twice - three times as fast in eclipse.

Why is this?

This loads once to get the images off of a sprite sheet (All images are buffered images)

SpriteMan(Map xMap, Board xBoard)
    {
        mMap = xMap;
        mBoard = xBoard;
        try
        {
            bigImg = ImageIO.read(new File("sprites.PNG"));
            background = ImageIO.read(new File("background.PNG"));
        }
        catch (IOException e) 
        {
            System.err.println("Caught IOException: " + e.getMessage());
        }

        for (int i = 0; i < rows; i++)
        {
            for (int j = 0; j < cols; j++)
            {
                sprites[i][j] = bigImg.getSubimage(i * width,j * height,width,height);

                iSprites[i][j] = config.createCompatibleImage(width, height, Transparency.TRANSLUCENT);
                //iSprites[i][j] = toImage(sprites[i][j]);

                for(int x = 0; x<32; x++)
                {
                    for(int y = 0; y<32; y++)
                    {
                        iSprites[i][j].setRGB(x, y, sprites[i][j].getRGB(x,y));
                    }
                }

                loadedImage+=1;

            }
        }

    }

After this, the sprites are saved to their corresponding objects (also only called once)

BlockGround(Map xMap, int X, int Y)
    {
        super(xMap, X, Y);

        mSprite = mMap.mBoard.mSpriteMan.sprites[0][0];
        mCollidable = true;
        mChar = 'G';
    }

The blocks are drawn using:

g2.drawImage(mSprite,null, x, y);

EDIT----- Thank you so much! The program runs normally now (After updating my JRE) although I seem to have messed something up and it took a lot of fiddling to get eclipse running again, but hey, it works!

Was it helpful?

Solution

Did you upload the jar to a webserver by any chance? If so, the slowdown may be caused by that server.

OTHER TIPS

My best guess is that eclipse is using a more stable version of java than your system is set to use by default. Can't really tell without some code.

---Edit---
in command prompt use "java -version" and set your eclipse project to use that. then it should be the same.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top