Java LibGDX:绘制50x50瓷砖的速度非常慢

Java LibGDX:绘制50x50瓷砖的速度非常慢,java,performance,libgdx,Java,Performance,Libgdx,我在上找到了一些创建平铺贴图并填充它的代码。在放大相机以绘制~50x50的瓷砖之前,一切正常。在这一点上,我得到~5 fps,输入几乎没有响应。以下是修改后的代码: public class Core extends ApplicationAdapter { private AssetManager am; private SpriteBatch batch; private BitmapFont font; private TiledMap map;

我在上找到了一些创建平铺贴图并填充它的代码。在放大相机以绘制~50x50的瓷砖之前,一切正常。在这一点上,我得到~5 fps,输入几乎没有响应。以下是修改后的代码:

public class Core extends ApplicationAdapter {

    private AssetManager am;
    private SpriteBatch batch;
    private BitmapFont font;
    private TiledMap map;
    private OrthogonalTiledMapRenderer renderer;
    private OrthographicCamera camera;
    private OrthoCamController cameraController;

    @Override
    public void create() {
        am = new AssetManager();
        am.load("tiles.png", Texture.class);
        am.finishLoading();

        float w = Gdx.graphics.getWidth();
        float h = Gdx.graphics.getHeight();

        batch = new SpriteBatch();
        batch.disableBlending();

        camera = new OrthographicCamera();
        camera.setToOrtho(false, (w / h) * 400, 400);
        camera.update();

        cameraController = new OrthoCamController(camera);
        Gdx.input.setInputProcessor(cameraController);

        font = new BitmapFont();

        map = new TiledMap();
        MapLayers layers = map.getLayers();
        TiledMapTileLayer layer = new TiledMapTileLayer(200, 200, 8, 8);
        TextureRegion[][] splitTiles = TextureRegion.split((Texture)am.get("tiles.png"), 8, 8);
        for (int x = 0; x < 1000; x++) {
            for (int y = 0; y < 1000; y++) {
                int ty = 1;
                int tx = 1;
                Cell cell = new Cell();
                cell.setTile(new StaticTiledMapTile(splitTiles[ty][tx]));
                layer.setCell(x, y, cell);
            }
            layers.add(layer);
        }
        renderer = new OrthogonalTiledMapRenderer(map, batch);
    }

    @Override
    public void render() {
        Gdx.gl.glClearColor(100f / 255f, 100f / 255f, 250f / 255f, 1f);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        camera.update();
        renderer.setView(camera);
        renderer.render();
    }

    @Override
    public void resize(int width, int height) {

    }

    @Override
    public void dispose() {
        am.dispose();
        map.dispose();
    }
}
公共类核心扩展了ApplicationAdapter{
私人资产管理人am;
专用SpriteBatch批次;
专用位图字体;
私人平铺地图;
私有正交瓦片渲染器;
私人正交摄影机;
专用摄像机控制器摄像机控制器;
@凌驾
公共void create(){
am=新资产管理器();
加载(“tiles.png”,Texture.class);
am.finishload();
float w=Gdx.graphics.getWidth();
float h=Gdx.graphics.getHeight();
批次=新的SpriteBatch();
batch.disableBlinding();
摄影机=新的正交摄影机();
摄像机。设置为(假,(宽高)*400400);
camera.update();
cameraController=新的正交摄像机控制器(摄像机);
Gdx.input.setInputProcessor(cameraController);
font=新的位图字体();
map=新的tileMap();
MapLayers layers=map.getLayers();
TiledMatipleLayer层=新的TiledMatipleLayer(200,200,8,8);
TextureRegion[][]splitTiles=TextureRegion.split((纹理)am.get(“tiles.png”),8,8);
对于(int x=0;x<1000;x++){
对于(int y=0;y<1000;y++){
int-ty=1;
int-tx=1;
单元格=新单元格();
cell.setTile(新的statictileMaptile(splitTiles[ty][tx]);
层。设置细胞(x,y,细胞);
}
图层。添加(图层);
}
渲染器=新的正交平铺贴图渲染器(贴图,批处理);
}
@凌驾
公共无效呈现(){
Gdx.gl.glClearColor(100f/255f、100f/255f、250f/255f、1f);
Gdx.gl.glClear(GL20.gl\u颜色\u缓冲\u位);
camera.update();
渲染器.setView(摄像机);
render.render();
}
@凌驾
公共空心调整大小(整型宽度、整型高度){
}
@凌驾
公共空间处置(){
am.dispose();
map.dispose();
}
}
我严重怀疑Libgdx不能处理这么多的tile,所以我的问题是:如何提高性能。。。还是我太野心勃勃了


我能找到的唯一解决方案是,但看起来他们删除了其中使用的方法。

您可能想放置
层。添加(层)在(intx=0;x<1000;x++)的
之外
循环哇,我真不敢相信我错过了。非常感谢你!