English 中文(简体)
日食时 Java 绘图比编译时快得多
原标题:Java drawImage much faster in eclipse compared to when compiled

当我从日食开始运行我的程序时, 它运行正常, CPU的负载很少。 JProfiler (观察日食运行的程序) 表示大部分被碰撞探测和绘制。 JPropiler 正在观看编译的罐子运行时, 97% 的 cpu 使用来自绘图。 它的运行速度是日食的两倍 - 三倍 。

为什么?

此加载一次以从图示工作表上获取图像( 所有图像都是缓冲图像)

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 ;
    }

这些区块是用下列方式绘制的:

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!

最佳回答

您有没有把罐子上传到网络服务器上? 如果是的话, 减速可能是由服务器造成的 。

问题回答

我最好的猜测是日食使用的是比您的系统默认使用更稳定的 java 版本。 没有代码, 无法辨别 。

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





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签