我正在用AndEngine GLES2創建遊戲。我正在嘗試在活動中加載圖像。但是每次運行應用程序時,它都會顯示出沒有錯誤的黑色方塊。以下是我的代碼:AndEngine顯示沒有錯誤的黑屏
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.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.region.TextureRegion;
import org.andengine.ui.activity.SimpleBaseGameActivity;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends SimpleBaseGameActivity {
private static final int CAMERA_WIDTH = 480;
private static final int CAMERA_HEIGHT = 640;
private BitmapTextureAtlas ourAtlas;
private TextureRegion ourCircle;
private Sprite circle;
@Override
public EngineOptions onCreateEngineOptions() {
final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
return new EngineOptions(true, ScreenOrientation.LANDSCAPE_SENSOR,
new RatioResolutionPolicy(CAMERA_WIDTH,CAMERA_HEIGHT), camera);
}
@Override
protected void onCreateResources() {
ourAtlas = new BitmapTextureAtlas(this.getTextureManager(),256,512);
ourCircle = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.ourAtlas,
this, "gfx/rectangle.png",0,0);
mEngine.getTextureManager().loadTexture(ourAtlas);
}
@Override
protected Scene onCreateScene() {
this.mEngine.registerUpdateHandler(new FPSLogger());
final Scene mScene = new Scene();
circle = new Sprite(32, 32, ourCircle, this.getVertexBufferObjectManager());
mScene.attachChild(circle);
mScene.setBackground(new Background(1.0f,1.0f,1.0f));
return mScene;
}
}
該活動完美無缺地運行。但屏幕中間顯示的是黑色方塊。我不明白爲什麼圖像沒有顯示。以下是該活動的截圖。
Click on this link to see the screenshot from my activity
我會喜歡它,如果有人會來看看什麼是錯的。我究竟做錯了什麼?