2014-10-19 30 views
0

我在寫一個使用LibGDX框架的android應用程序。我目前遇到了一個問題,在安裝我的應用程序(通過Eclipse或手動使用.apk安裝程序)後,某些.png資產將無法呈現到屏幕上。爲什麼第一次運行後我的android資源不會加載?

完成初始安裝後,所有內容在第一次運行時都按預期工作。但是之後,我的一些資產將不會呈現。沒有例外;圖像被加載,他們只是沒有渲染到屏幕上。我檢查了/data/app/<appname>中安裝的.apk,我使用的紋理包文件和圖像都存在,並且看起來應該如此。

創建包文件的代碼是從我寫的另一個項目複製而來的,並且紋理加載的實現是相同的。這兩個項目中的所有依賴項和api版本都是相同的,我只是在新應用程序中遇到這種情況。

只要我使用eclipse調試器運行並觀察程序,.apk就會被重新加載,因此問題就會消失......第一次運行。我也嘗試重新安裝位於/data/app.apk,然後該程序將工作...第一次運行。

我已經嘗試將違規的.png文件重新導出爲新的.png s,這並沒有幫助。我曾嘗試將它們導出爲.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 
+0

請提供可能的最小代碼示例來說明您遇到的問題。 – 2014-10-19 20:44:20

+0

在代碼執行期間發佈有問題的代碼片段或生成一些日誌文件可能會有幫助。 – 2014-10-19 20:49:36

+1

沒有看到代碼,我的第一個猜測是你正在使用靜態。不要使用(非最終)靜態字段,如果您不特別關心它們,它們會在Dalvik上造成問題。 – Xoppa 2014-10-19 21:15:01

回答

0

原來的應用程序在後臺運行。

相關問題