2012-07-25 171 views
1

我開始使用AndEngine並嘗試加載紋理以在屏幕中生成精靈。 在我的活動我班有AndEngine支持的設備

public EngineOptions onCreateEngineOptions() { 

    DisplayMetrics dm = new DisplayMetrics(); 
    getWindowManager().getDefaultDisplay().getMetrics(dm); 

    CAMERA_WIDTH = dm.widthPixels; 
    CAMERA_HEIGHT = dm.heightPixels; 

    float screenResolutionRatio = ((float)CAMERA_WIDTH/(float)CAMERA_HEIGHT); 

    this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT); 
    final EngineOptions options = new EngineOptions(true, 
                ScreenOrientation.PORTRAIT_FIXED, 
                new RatioResolutionPolicy(screenResolutionRatio), 
                this.mCamera); 
     return options; 
    } 


public void onCreateResources(OnCreateResourcesCallback arg0) 
      throws Exception { 
     mTextures = new NTTextures(this);  

    } 

NTTexture就是紋理被裝載的類。

這裏是代碼的meaningfull部分:

public NTTextures(final BaseGameActivity activity) { 
    try 
    { 
     BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/"); 
      this.spritesheetTexturePack = new TexturePackLoader(activity.getAssets(), activity.getTextureManager()).loadFromAsset("gfx/baseAtlas.xml", "gfx/"); 
     this.mSpritesheetTexture = spritesheetTexturePack.getTexture(); 
     this.mSpritesheetTexturePackTextureRegionLibrary = spritesheetTexturePack.getTexturePackTextureRegionLibrary(); 
     this.ping= this.mSpritesheetTexturePackTextureRegionLibrary.get(baseAtlas.PING_ID); 

     activity.getEngine().getTextureManager().loadTexture(this.mSpritesheetTexture); 


    } catch (final TexturePackParseException e) { 
      Log.e("Error", String.valueOf(e)); 
     } 

     } 

這樣,那麼這一切後,我有一個錯誤日誌等和崩潰。

07-25 18:44:23.880: D/AndEngine(32659): NTGameActivity.onCreate @(Thread: 'main') 
07-25 18:44:23.930: W/dalvikvm(32659): VFY: unable to resolve static method 391: Landroid/opengl/GLES20;.glVertexAttribPointer (IIIZII)V 
07-25 18:44:24.100: D/AndEngine(32659): NTGameActivity.onResume @(Thread: 'main') 
07-25 18:44:24.290: D/AndEngine(32659): VERSION: OpenGL ES 2.0 1309647 
07-25 18:44:24.290: D/AndEngine(32659): RENDERER: Adreno 200 
07-25 18:44:24.290: D/AndEngine(32659): EGLCONFIG: EGLConfig(Red=5, Green=6, Blue=5, Alpha=0, Depth=0, Stencil=0) 
07-25 18:44:24.290: D/AndEngine(32659): EXTENSIONS: GL_AMD_compressed_3DC_texture GL_AMD_compressed_ATC_texture GL_AMD_performance_monitor GL_AMD_program_binary_Z400 GL_EXT_texture_filter_anisotropic GL_EXT_texture_format_BGRA8888 GL_EXT_texture_type_2_10_10_10_REV GL_OES_compressed_ETC1_RGB8_texture GL_OES_depth_texture GL_OES_depth24 GL_OES_EGL_image GL_OES_element_index_uint GL_OES_fbo_render_mipmap GL_OES_fragment_precision_high GL_OES_get_program_binary GL_OES_packed_depth_stencil GL_OES_rgb8_rgba8 GL_OES_standard_derivatives GL_OES_texture_3D GL_OES_texture_float GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_OES_texture_npot GL_OES_vertex_half_float GL_OES_vertex_type_10_10_10_2 GL_NV_fence GL_QCOM_driver_control GL_QCOM_perfmon_global_mode GL_QCOM_extended_get GL_QCOM_extended_get2 GL_QCOM_tiled_rendering GL_QCOM_writeonly_rendering GL_QCOM_memory_monitor 
07-25 18:44:24.290: D/AndEngine(32659): MAX_VERTEX_ATTRIBS: 16 
07-25 18:44:24.290: D/AndEngine(32659): MAX_VERTEX_UNIFORM_VECTORS: 251 
07-25 18:44:24.290: D/AndEngine(32659): MAX_FRAGMENT_UNIFORM_VECTORS: 222 
07-25 18:44:24.300: D/AndEngine(32659): MAX_TEXTURE_IMAGE_UNITS: 16 
07-25 18:44:24.300: D/AndEngine(32659): MAX_TEXTURE_SIZE: 4096 
07-25 18:44:24.300: D/AndEngine(32659): NTGameActivity.onSurfaceCreated @(Thread: 'GLThread 9') 
07-25 18:44:24.300: D/AndEngine(32659): NTGameActivity.onCreateGame @(Thread: 'GLThread 9') 
07-25 18:44:24.310: D/AndEngine(32659): NTGameActivity.onCreateResources @(Thread: 'GLThread 9') 
07-25 18:44:30.310: I/global(32659): Default buffer size used in BufferedInputStream constructor. It would be better to be explicit if an 8k buffer is required. 
07-25 18:44:30.420: D/AndEngine(32659): NTGameActivity.onSurfaceChanged(Width=320, Height=480) @(Thread: 'GLThread 9') 
07-25 18:44:31.000: W/dalvikvm(32659): VFY: unable to resolve static method 353: Landroid/opengl/GLES20;.glDrawElements (IIII)V 
07-25 18:44:31.000: W/dalvikvm(32659): VFY: unable to resolve static method 391: Landroid/opengl/GLES20;.glVertexAttribPointer (IIIZII)V 
07-25 18:44:31.030: W/dalvikvm(32659): Exception Lorg/andengine/util/exception/AndEngineRuntimeException; thrown during Lorg/andengine/opengl/GLES20Fix;.<clinit> 

我用於測試LG Optimus One與Android 2.2,所以我認爲我的設備沒有需要的GLES庫。這是錯誤的原因還是我的代碼中有錯誤?另外,有沒有AndEngine支持的設備列表?

此外: 我檢查了測試的手機規格 - 它有Adreno 200支持OpenGLES 2.0。所以,它一定需要庫,但它不需要。有什麼建議麼?

回答

2

你可以試試這個方法:AndEngine.isDeviceSupported()

+0

這就是我需要的! – 2012-07-26 12:12:16

4

要確保部署失敗的,因爲你的設備上的錯誤的OpenGL版本,你可以插入你的清單文件中的以下行:

<uses-feature android:glEsVersion="0x00020000" /> 

Eclipse將不會讓您部署的設備上的應用程序,不支持OpenGL ES 2.0。此外,這還會阻止擁有舊設備的用戶從Google Play下載您的應用。希望這可以幫助。

+0

謝謝,補充說,但仍然有同樣的錯誤。 – 2012-07-25 16:00:03

+0

我已經在另一部手機上運行該應用程序 - 完美工作。所以,這是關於不可接受的設備,並且沒有幫助禁止運行我的設備。 – 2012-07-25 16:51:40