# TiledMap taking a lot of time to load in libgdx

I am developing a game using libGdx in which a level has 2400 * 450 tiles Map and each tile is of 4 pixels. I am also using box2d in my game.

My problem is that when I run the game on my phone it takes a lot of time to load the screen (more than a minute). How can I reduce this loading time?

I created tilemap using Tiled and I am using Android Studio.

Below is my code (SCALE is 2.0f and PPM is 4)

@Override
public void show() {
w = Gdx.graphics.getWidth();
h = Gdx.graphics.getHeight();

camera = new OrthographicCamera();
camera.setToOrtho(false, w / SCALE, h / SCALE);
camera.update();
viewport = new FitViewport(w / SCALE, h / SCALE  ,camera);
viewport.apply();
.
.
.

tmr = new OrthogonalTiledMapRenderer(map, 1/SCALE);

}

@Override
public void render(float delta) {
update(Gdx.graphics.getDeltaTime());

//Render
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

tmr.render();

.
.
.
b2dr.render(world, camera.combined.scl(PPM));
}

public void update(float delta) {

world.step(1 / 60f, 6, 2);
cameraUpdate(delta);
tmr.setView(camera);
batch.setProjectionMatrix(camera.combined);
}

@Override
public void resize(int width, int height) {
camera.setToOrtho(false, width / SCALE, height / SCALE);

viewport.update( width , height );
}


• Is all of this code relevant? If not please just include the relevant code (probably the loading of the map itself). – Charanor Mar 14 '17 at 17:15
• @Charanor now the irrelevant code is removed , please help . – ZaidRehman Mar 14 '17 at 19:12
• Have you tried using an AssetManager to load your map? I have a feeling this would increase your performance by a bit at least. Also take a look at loadSync() and loadASync() in the TmxMapLoader class. – Charanor Mar 14 '17 at 19:28
• Are you certain that the long load time is because of the TmxMapLoader? Could it perhaps be to do with how you are combining the tiledmap with box2D? It is difficult to say without the full code, but are you creating many box2D bodies when the map is loaded? If not, how big is the actual .tmx file? I find it odd that loading this presumably simple/small file would take such a long time. You could also try launching your app in debug, and then using Android Studio's profiling to pinpoint the exact operations that are causing the slow-down. – grimrader22 Mar 20 '17 at 7:15

I solved the problem by reducing the tiles in a map and increased individual tile size (from 4 * 4 pixel to 64 *64 pixels)

Moreover i used Asset manager to load the tiles . Thanx @Charanor

Now it completely smooth and takes very less time to load.