首次运行后为什么我的android资产不会加载?

时间:2014-10-19 20:41:53

标签: java android libgdx

我正在使用LibGDX框架编写一个Android应用程序。我目前遇到的问题是,在安装了我的应用程序之后(通过Eclipse或使用.apk安装程序手动),某些.png资产将无法呈现到屏幕上。

执行初始安装后,所有内容在第一次运行时都按预期工作。然而,在那之后,我的一些资产将无法呈现。没有例外;图像被加载,它们只是没有渲染到屏幕上。我已经检查了.apk中已安装的/data/app/<appname>,我正在使用的纹理包文件和图像都在那里,看起来应该是这样。

用于创建包文件的代码是从我编写的另一个项目中复制的,并且纹理加载的实现是相同的。这两个项目之间的所有依赖项和api版本都是相同的,我只是在新应用程序上遇到这种情况。

一旦我使用eclipse调试器运行并观察程序,就会重新加载.apk,因此问题就会消失......对于第一次运行。我还尝试重新安装.apk中的/data/app,然后该程序将首次运行。

我尝试将有问题的.png文件重新导出为新的.png,但这没有帮助。我已经尝试将它们导出为.jpg,但这没有帮助。这让我脱掉了头发!有谁知道这个问题是什么?

编辑:

Game.java

...
@Override
public void create() {
    TEXTURES = new TextureAtlas(Gdx.files.internal("textures/textures.pack"));
    WIDTH = Gdx.app.getGraphics().getWidth();
    HEIGHT = Gdx.app.getGraphics().getHeight();
    this.setScreen(new IntroScreen());
    startTime = System.currentTimeMillis();
}
...

ButtonRenderer.java

...
private ButtonRenderer() {
    playButton = createButton("play", "play_dark", "play_dark",
            buttonSize, buttonSize);
    pauseButton = createButton("pause", "pause_dark", "pause_dark",
            buttonSize, buttonSize);
    stopButton = createButton("stop", "stop_dark", "stop_dark",
            buttonSize, buttonSize);
    recordButton = createButton("record", "record_dark", "record_dark",
            buttonSize, buttonSize);
    addButtons(playButton, pauseButton, stopButton, recordButton);
}

private ImageButton createButton(String iconName, String downIconName, String checkedIconName,
        int width, int height) {
    Sprite defaultSprite = Game.TEXTURES.createSprite(iconName);
    defaultSprite.setSize(width, height);
    SpriteDrawable defaultDrawable = new SpriteDrawable(defaultSprite);

    Sprite downSprite = Game.TEXTURES.createSprite(downIconName);
    downSprite.setSize(width, height);
    SpriteDrawable downDrawable = new SpriteDrawable(downSprite);

    Sprite checkedSprite = Game.TEXTURES.createSprite(checkedIconName);
    checkedSprite.setSize(width, height);
    SpriteDrawable checkedDrawable = new SpriteDrawable(checkedSprite);

    return new ImageButton(defaultDrawable, downDrawable, checkedDrawable);
}

public void addButtons(ImageButton... buttons) {
    for (ImageButton button : buttons) {
        addButton(button);
    }
}

public void addButton(ImageButton button) {
    buttons.add(button);
    stage.addActor(button);
    button.setPosition(buttonSize * this.buttons.size(), 0);
    button.setSize(buttonSize, buttonSize);
    button.pack();
}

public void render(float delta, GL20 gl) {
    stage.act(delta);
    batch.begin();
    stage.draw();
    batch.end();
}
...

日志

10-19 20:40:18.423: D/Sampling Rate Check(14289): Attempting rate 44100Hz, bits: 2, channel: 12
10-19 20:40:18.623: I/AndroidInput(14289): sensor listener setup
10-19 20:40:18.723: W/GL2JNIView(14289): creating OpenGL ES 2.0 context
10-19 20:40:18.743: I/AndroidGraphics(14289): OGL renderer: NVIDIA Tegra
10-19 20:40:18.743: I/AndroidGraphics(14289): OGL vendor: NVIDIA Corporation
10-19 20:40:18.743: I/AndroidGraphics(14289): OGL version: OpenGL ES 2.0
10-19 20:40:18.743: I/AndroidGraphics(14289): OGL extensions: GL_NV_platform_binary GL_OES_rgb8_rgba8 GL_OES_fbo_render_mipmap GL_NV_depth_nonlinear GL_NV_draw_path GL_OES_EGL_image GL_OES_vertex_half_float GL_NV_framebuffer_vertex_attrib_array GL_NV_coverage_sample GL_OES_mapbuffer GL_ARB_draw_buffers GL_EXT_Cg_shader GL_EXT_packed_float GL_OES_texture_half_float GL_OES_texture_float GL_EXT_texture_array GL_OES_compressed_ETC1_RGB8_texture GL_EXT_texture_compression_latc GL_EXT_texture_compression_dxt1 GL_EXT_texture_compression_s3tc GL_EXT_texture_filter_anisotropic GL_NV_get_tex_image GL_NV_read_buffer GL_NV_shader_framebuffer_fetch GL_NV_fbo_color_attachments GL_EXT_bgra GL_EXT_texture_format_BGRA8888 GL_EXT_unpack_subimage 
10-19 20:40:18.753: I/AndroidGraphics(14289): framebuffer: (5, 6, 5, 0)
10-19 20:40:18.753: I/AndroidGraphics(14289): depthbuffer: (16)
10-19 20:40:18.753: I/AndroidGraphics(14289): stencilbuffer: (0)
10-19 20:40:18.753: I/AndroidGraphics(14289): samples: (0)
10-19 20:40:18.753: I/AndroidGraphics(14289): coverage sampling: (false)
10-19 20:40:18.753: I/AndroidGraphics(14289): Managed meshes/app: { }
10-19 20:40:18.753: I/AndroidGraphics(14289): Managed textures/app: { }
10-19 20:40:18.763: I/AndroidGraphics(14289): Managed shaders/app: { }
10-19 20:40:18.763: I/AndroidGraphics(14289): Managed buffers/app: { }
10-19 20:40:24.943: I/AndroidGraphics(14289): paused
10-19 20:40:25.033: I/AndroidInput(14289): sensor listener tear down
10-19 20:40:25.033: I/AndroidGraphics(14289): Managed meshes/app: { }
10-19 20:40:25.033: I/AndroidGraphics(14289): Managed textures/app: { }
10-19 20:40:25.033: I/AndroidGraphics(14289): Managed shaders/app: { }
10-19 20:40:25.033: I/AndroidGraphics(14289): Managed buffers/app: { }
10-19 20:40:25.033: I/AndroidGraphics(14289): destroyed
10-19 20:40:25.413: W/IInputConnectionWrapper(14289): showStatusIcon on inactive InputConnection

1 个答案:

答案 0 :(得分:0)

原来应用程序进程在后台运行。