质地不显示在应用程序 [英] Texture is not displayed in the application

查看:119
本文介绍了质地不显示在应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在学习libgdx我发现了一个美妙的方式,以项目结构框架的过程。这是我的一个加载的纹理和显示它的一个例子。

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.

AssetManager的实现Singleton模式

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(){}
}

加载的图片

    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);
    }
}
...
}

和finaly显示图片

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.

推荐答案

尝试实行一次性您GameAsssetManager类,并释放所有资源dispose()方法。对于我的资产管理公司我用单,以及和我没有任何内存问题和其他的东西。我的意思是,在像的onPause,的onStop,的onDestroy生命周期方法的释放。而且可以肯定,你将重新加载你的资源,当您重新启动应用程序。

Try to implement Disposable to your GameAsssetManager class and release all resources in dispose() method. For my asset manager I use singleton as well and I don't have any memory issues and other stuff. I mean, release in life cycle methods like "onPause", "onStop", "onDestroy". And be sure that you will reload you resources when you start an application again.

这篇关于质地不显示在应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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