gpt4 book ai didi

Java 2D : Render a very large amount of tiles on screen quickly

转载 作者:行者123 更新时间:2023-12-01 15:29:43 24 4
gpt4 key购买 nike

如果有人能胜任的话,还有一个简单的问题。我有这个代码:

        for(int cy = 0; cy < 3; cy++) {
for(int cx = 0; cx < 3; cx++) {
for(int y = 0; y < 16; y++) {
for(int x = 0; x < 16; x++) {
g2D.drawImage(Tiles.tileImages.get(C0.chunk[x][y][cx][cy]),
C0.cX[cx][cy] * cspcr + (blckspcr * x) + width - pXspcr,
C0.cY[cx][cy] * cspcr + (blckspcr * y) + height - pYspcr + (int)(24.25 * zoom),
blckspcr, blckspcr, null);
if(C0.chunk[x][y][cx][cy].equals("a05")) {
g2D.drawImage(Tiles.treetop,
C0.cX[cx][cy] * cspcr + (blckspcr * x) + width - pXspcr,
C0.cY[cx][cy] * cspcr + (blckspcr * y) + height - pYspcr + (int)(24.25 * zoom) - blckspcr,
blckspcr, blckspcr, null);
}
}
}
}
}

但我的问题是,它在我的应用程序中造成了令人难以置信的大量滞后。有什么方法可以避免使用我拥有的大量循环或可能加快它的速度?它首先绘制的图像是从 4D 字符串数组中的 block 中抓取 block ,并根据字符串从 HashMap 中获取图像,然后使用一堆数字绘制图像。如果有人可以提供帮助,我将不胜感激。谢谢!

最佳答案

您需要以不同的方式存储数据(4D 数组几乎总是一个坏主意)。

如果适合您的用例,您可以开始用散列替换这些 4D 字符串数组(那么您只有一个循环)。

关于Java 2D : Render a very large amount of tiles on screen quickly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9694505/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com