我正在学习 AndEngine,并且正在学习一些基本教程。我试图在屏幕中加载一个精灵,但精灵看起来已损坏。
这是我的代码:
package com.example.andengine_demo;
import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.sprite.Sprite;
import org.andengine.entity.util.FPSLogger;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.region.TextureRegion;
import org.andengine.ui.activity.BaseGameActivity;
public class MainActivity extends BaseGameActivity {
// ===========================================================
// Constants
// ===========================================================
static final int CAMERA_WIDTH = 720;
static final int CAMERA_HEIGHT = 480;
private static final String TAG = "AndEngineTest";
private BitmapTextureAtlas mBitmapTextureAtlas;
private TextureRegion mPlayerTextureRegion;
// ===========================================================
// Fields
// ===========================================================
//private ZoomCamera mCamera;
@Override
public EngineOptions onCreateEngineOptions() {
// TODO Auto-generated method stub
Camera mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
return new EngineOptions(true, ScreenOrientation.LANDSCAPE_SENSOR, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
}
@Override
public void onCreateResources(
OnCreateResourcesCallback pOnCreateResourcesCallback) throws Exception {
// TODO Auto-generated method stub
mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 32, 32, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "face_box.png", 0, 0);
mBitmapTextureAtlas.load();
}
@Override
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback)
{
this.mEngine.registerUpdateHandler(new FPSLogger());
// TODO Auto-generated method stub
Scene scene = new Scene();
scene.setBackground(new Background(0f, 0f, 1f));
final Sprite oPlayer = new Sprite(32,32, mPlayerTextureRegion, getVertexBufferObjectManager());
scene.attachChild(oPlayer);
}
@Override
public void onPopulateScene(Scene pScene,
OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception {
// TODO Auto-generated method stub
}
}
这就是它的外观:
我检查了图像大小是 32x32,图像的路径,并且在加载时我还尝试了不同的纹理选项。图片格式为PNG。如果您看到,背景颜色与我设置的颜色不符。我认为我的模拟器已正确配置(使用 GPU 仿真)以使用 GLES2.0。我认为问题可能是相机高度和相机宽度的值。我之所以设置它是因为我在教程中看到了它们,但不知道它们是否正确……我的分辨率是 WVGA800。
我不知道我做错了什么......我需要解决这个问题才能继续创建游戏,所以任何帮助都会受到好评。
谢谢!