AndEngine shows black screen with no errors

91 Views Asked by At

I am creating a game with AndEngine GLES2. I am trying to load an image in the activity. But everytime I run the app it just shows little black square with no errors. Below is my code :

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



}

The activity runs perfectly without any errors. But the screen shows little black square in the middle. I do not understand why the image is not showing. Below is the screenshot from the activity.

Click on this link to see the screenshot from my activity

I would love it if someone would take a look at what's wrong. What am I doing wrong?

2

There are 2 best solutions below

0
Neel Patel On BEST ANSWER

I found the solution.

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

In the line above, I have to change the width and the height of the atlas to 1024,1024 and it worked our perfectly. The problem was in my size.

0
mrkernelpanic On

Try to load textures Like this:

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

    }

}

Also try to set first the Background and then attach the children.