我开始使用 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 是一个加载纹理的类。
这是代码中有意义的部分:
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>
我用 Android 2.2 测试 LG Optimus One,所以我认为我的设备不需要 GLES 库。这是错误的原因还是我的代码中有错误?另外,是否有 AndEngine 支持的设备列表?
另外: 我检查了测试过的手机规格——它具有支持 OpenGLES 2.0 的 Adreno 200。所以,它一定需要库,但它不需要。有什么建议么?