LIBGDX白色纹理Android上的第一次运行 [英] LIBGDX White textures in the first run on android

查看:189
本文介绍了LIBGDX白色纹理Android上的第一次运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建使用LIBGDX一个游戏,它在台式机工作正常。当我安装它,并使用安装向导,打开它(?),直到我回家或锁定,然后恢复它正常工作。然后,它仅显示白框而不是质地,当我回家或锁定它的声音仍在运行。之后,我完全退出的声音停止运行。但是当我再次运行错误不会再次不管多少次,我打开游戏发生。

I created a game using LIBGDX and it works fine in desktop. When I install it and open it using the install wizard(?) It works fine until I go home or lock it and then resume it. Then it shows only white boxes instead of texture and when I go home or lock it the sounds are still running. After I exit completely the sounds stop running. But when I run it again the error doesn't happen again no matter how many times I open the game.

有仅发生在这种情况下,如果我拳头关闭安装向导,并打开它通常问题不要么发生

It only happens in that case, if i fist close the install wizard and open it normally the problem doesn't happen either.

这是我的code:

public class MyGame extends Game {

public static final AssetManager MANAGER = new AssetManager();

public SpriteBatch SB;

public final AbstractScreen GAMEOVER, LOADING, MAIN, GAMEPLAY;

public MyGame() {
    GAMEOVER = new GameOverScreen(this);
    GAMEPLAY = new GameplayScreen(this); 
    LOADING = new LoadingScreen(this);
    MAIN = new MainScreen(this); 
}

@Override 
public void create() { 
    Texture.setEnforcePotImages(false); 

    SB = new SpriteBatch();

    MANAGER.load("xxx.png", Texture.class);
    MANAGER.load("xxx.png", Texture.class);
    MANAGER.load("xxx.png", Texture.class);
    MANAGER.load("xxx.png", Texture.class);
    MANAGER.load("xxx.png", Texture.class);
    MANAGER.load("xxx.png", Texture.class);
    MANAGER.load("xxx.png", Texture.class);


    MANAGER.load("xxx.wav", Sound.class);
    MANAGER.load("xxx.wav", Sound.class);

    setScreen(LOADING);
}

@Override
public void dispose() {
    super.dispose();
    MANAGER.dispose();
    SB.dispose();
}
}

此外,我用不同的屏幕。

Also i use different screens.

我希望有人能帮助我与此有关。

I hope someone could help me with this.

编辑。下面是什么Basimm回答我已将此添加到我的code:

EDIT. Following what Basimm answered i added this to my code:

@Override
public void pause() {
    MANAGER.clear();
}

@Override
public void resume() {
    MANAGER.load("xxx.png", Texture.class);
    MANAGER.load("xxx.png", Texture.class);
    MANAGER.load("xxx.png", Texture.class);
    MANAGER.load("xxx.png", Texture.class);
    MANAGER.load("xxx.png", Texture.class);
    MANAGER.load("xxx.png", Texture.class);
    MANAGER.load("xxx.png", Texture.class);


    MANAGER.load("xxx.wav", Sound.class);
    MANAGER.load("xxx.wav", Sound.class);

    this.setScreen(LOADING);
}

我不得不添加的setScreen(LOADING);东阳当我锁定了纹理设备白色一次。

I had to added the setScreen(LOADING); beacause when i locked the device the textures got white again.

推荐答案

这是一个常见的​​错误,因为当Android设备进入暂停状态,所以如果你在你的应用程序监听器看起来会有一个恢复的纹理被自动卸载()函数,当应用程序被再次加载时,将调用,你必须确保你重新加载所有资产后,然后再恢复已暂停。

This is a common error because when the android device goes into a pause state the textures are automatically unloaded so if you look in you application listener there will be a resume() function that will be called when the application is loaded again, you will have to make sure that you reload all of your assets after it has been paused then resumed again.

于是再次拨打您的经理加载功能在你的简历的方法,因为它需要重新加载,并叫来经理的clear()函数中的停顿方法,使其清空所有加载的资源。

So call your managers load functions in your resume method again because it will need to be loaded again, and call the manager's clear() function in the pause method so that it empties all loaded assets.

这篇关于LIBGDX白色纹理Android上的第一次运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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