如何减少libgdx中所有资产的加载时间 [英] How to decrease loading time of all Assets in libgdx

查看:54
本文介绍了如何减少libgdx中所有资产的加载时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用libgdx制作游戏.我使用AssetManager类加载资产.当我开始游戏时,需要花费更多时间在Android设备上加载资产并显示黑屏.如何解决该问题.

I am making a game in libgdx. I use AssetManager class to load assets. When I start my game its takes more time to load assets on android device and show black screen at that time.How can I resolve that problem.

推荐答案

它将显示一个空白屏幕. 为了解决此问题,您可以在完成资产加载时渲染某些内容,并在完成加载后切换到菜单屏幕.

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.

希望这对您有所帮助.

这篇关于如何减少libgdx中所有资产的加载时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆