In the process of studying the framework libgdx I found a wonderful way to structure the project. And here's my example of loading a texture and displaying it.
realizing Singleton pattern of AssetManager
public class GameAsssetManager extends AssetManager {
private static GameAsssetManager instance;
public static GameAsssetManager getInstance(){
if(null == instance)
instance = new GameAsssetManager();
return instance;
}
public void init(){}
}
loading the picture
public class LoadScreen implements Screen{
private void loadAssets(){
GameAsssetManager.getInstance().load("badlogic.jpg",Texture.class);
}
@Override
public void show() {
GameAsssetManager.getInstance().init();
loadAssets();
}
@Override
public void render(float delta) {
//Метод update возвращает true в том случаи, если все ресурсы загружены
if(GameAsssetManager.getInstance().update()){
ScreenManager.getInstance().show(CustomScreen.GAME);
}
}
...
}
and finaly displaying the picture
public class GameScreen implements Screen {
...
@Override
public void show() {
batch = new SpriteBatch();
texture = GameAsssetManager.getInstance().get("badlogic.jpg");
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 1, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(
texture,
Gdx.graphics.getWidth()/2 - texture.getWidth()/2,
Gdx.graphics.getHeight()/2 - texture.getHeight()/2
);
batch.end();
}
...
So the problem is the following. When the application is compiled everything works fine. But if you close the application and launch the installed application anew, in the place where there should be displayed texture is displayed black square.