How to decrease loading time of all Assets in libgdx

女生的网名这么多〃 提交于 2019-12-02 06:15:59

Well it will show a blank screen. In order to solve this problem you can render something while loading of assets is done and as the loading is done you switch to menu screen.

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.GLCommon;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.shooter.waste.of.a.game.Assets;
import com.shooter.waste.of.a.game.utils.Game;
import com.shooter.waste.of.a.game.utils.Screen;

public  class LoadingScreen extends Screen{


public AssetManager manager;
SpriteBatch batcher;
Game game;
OrthographicCamera cam;
TextureAtlas load;
float stateTime;
AtlasSprite bg;
public LoadingScreen(Game game,SpriteBatch batcher) {
    super(game);
    this.batcher = batcher;
    this.game = game;
    manager = new AssetManager();
    manager.load("data/shoot",TextureAtlas.class);
    manager.load("data/b.jpg",Texture.class);

    cam = new OrthographicCamera(480, 800);
    cam.position.set(480 / 2, 800 / 2,0);
            load = new TextureAtlas("data/load");
            bg = new AtlasSprite(load.findRegion("loadingscrnbg"));




    }

    @Override
    public void render(float deltaTime)
    {
        update(deltaTime);
    GLCommon gl = Gdx.gl;
    gl.glClearColor(0, 0, 1f, 0.1f);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    cam.update();
    batcher.setProjectionMatrix(cam.combined);
    batcher.begin();
            batcher.draw(bg, 0, 0);

    batcher.enableBlending();
    batcher.end();



}

@Override
public void pause() {
    // TODO Auto-generated method stub

}

@Override
public void resume() {
    // TODO Auto-generated method stub

}

@Override
public void dispose() {
    // TODO Auto-generated method stub

}

@Override
public void update(float deltaTime) 
{
    if(manager.update())  \\ gives true when all assets are loaded
    {
        Assets.load(manager);
        game.setScreen(new GameScreen(game, batcher));
    }
}

@Override
public void backKeyPressed() {
    // TODO Auto-generated method stub

}


 }

One important thing is that it will still show a blank screen for those sprites which u want to render during the loading to try to render only few things and no sounds at all.

Hope this helps u out.

all you can do is you can add a loadng screen in the starting of your game and can play some music that time.

in this way user will know that the game is loading .. load all your assests in this screen and show a progress barr...

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!