AndEngine显示黑屏没有错误

AndEngine shows black screen with no errors

我正在使用 AndEngine GLES2 创建游戏。我正在尝试在 activity 中加载图像。但每次我 运行 应用程序时,它只会显示没有错误的小黑方块。下面是我的代码:

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;
        }



}

activity运行完美无误。但是屏幕在中间显示小黑方块。我不明白为什么图像没有显示。以下是来自 activity 的屏幕截图。

Click on this link to see the screenshot from my activity

如果有人能看看哪里出了问题,我会很高兴。我做错了什么?

尝试像这样加载纹理:

 public void onCreateResources() {

    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");


    this.mBuildableBitmapTextureAtlas = new BuildableBitmapTextureAtlas(this.getTextureManager(), 512, 512);

    this.yourTexture = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBuildableBitmapTextureAtlas, this, "yourimage.png");


    try {

        this.mBuildableBitmapTextureAtlas.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 0, 0));

        this.mBuildableBitmapTextureAtlas.load();

    } catch (TextureAtlasBuilderException e) {

        Debug.e(e);

    }

}

也尝试先设置背景,然后附加子项。

我找到了解决方案。

 ourAtlas = new BitmapTextureAtlas(this.getTextureManager(),256,512);

在上面的行中,我必须将图集的宽度和高度更改为 1024,1024,它完美地工作了。问题出在我的尺寸上。