5

I am writing a game for Android using AndEngine GLES 2. Everything was working properly - I had a background image, there were sprites moving around and even some music - until recently I tried something new (I wanted to be able to switch between two different scenes) when the display turned black.

I could still execute the game and there were no error shown. All log entries I made during the game were shown, even the music was playing so I knew the game was running "properly", but I couldn't see any image. Nothing. All black.

So I thought, changing everything back to before this "error" appeared, would do the trick. But still the screen is black.

I even tried commenting everything out but the background image - nothing.

Now if it is not too much to ask, could anyone please look over this short piece of code and tell me what is wrong there?

This are the variables I use:

private SmoothCamera camera;
private BitmapTextureAtlas bitmapTextureAtlas;  
private Scene scene;
private Sprite background;

The EngineOptions I never changed, so they should be alright.

@Override
public EngineOptions onCreateEngineOptions() {
    float positionX = 80f; // horizontal (x) position of the camera
    float positionY = 280f; // vertical (y) position of the camera
    float velocityX = 200f; // velocity of the horizontal camera movement
    float velocityY = 200f; // velocity of the vertical camera movement
    float zoomFactor = 1f; // the camera's zoom Factor (standard := 1)
    this.camera = new SmoothCamera(positionX, positionY, this.getWindowManager().getDefaultDisplay().getWidth(), this.getWindowManager().getDefaultDisplay().getHeight(), velocityX, velocityY, zoomFactor);
    EngineOptions options = new EngineOptions(true, ScreenOrientation.LANDSCAPE_SENSOR, new RatioResolutionPolicy(this.camera.getWidth(), this.camera.getHeight()), this.camera);
    return options;
}

Here I create the TextureAtlas and load a background image.

@Override
protected void onCreateResources() {
    // create the TextureAtlas
    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
    this.bitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1600, TextureOptions.NEAREST);

    // background
    this.background = new Sprite(0, 0, BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.bitmapTextureAtlas, this, "background.png", 0, 0, 1, 1), this.getVertexBufferObjectManager());
    this.mEngine.getTextureManager().loadTexture(this.bitmapTextureAtlas);
}

And finally the Scene is instantiated and the background gets attached.

@Override
protected Scene onCreateScene() {
    this.scene = new Scene();
    this.scene.attachChild(this.background);        
    return this.scene;
}

Now why would this small Activity not show? I forgot: its a SimpleBaseGameActivity.

Well, since AndEngine GLES2 is not running on the emulator, I have to use my phone (Samsung Galaxy GIO) and can't test the app on another machine.

Did anyone stumble upon a similar problem? Any help is really much appreciated and thank you for your time !

  • Christoph
Aviram Fireberger
  • 3,910
  • 5
  • 50
  • 69
GameDroids
  • 5,584
  • 6
  • 40
  • 59
  • OK, I created a new project with only this Activity above. It didn't work - and still no error messages. Now I am completely lost ... – GameDroids May 04 '12 at 12:05
  • 2
    The problem is gone now... I can't say that it is solved, since I still don't have any idea what went wrong, but it's working again (well, only the background screen, not the complete game I had before) After many years in computer science, I thought the "Have you tried switching it off and on again?" solution could always be avoided -- wrong! After uninstalling and deleting every trace of my app from my phone and rebooting everything, it suddenly started working again. Sorry if I wasted your time. Hope this "thing" never happens again! regards christoph – GameDroids May 04 '12 at 12:36

1 Answers1

1

I think the problem is here:

this.bitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 1024, 1600, TextureOptions.NEAREST);

The dimensions of the Atlas are supposed to be powers of 2.

Joseph Mansfield
  • 108,238
  • 20
  • 242
  • 324
  • 1
    yes, unfortunately the atlas still should have a size of the power of 2. Although GLES 2 supposedly supports atlases of any size. However some devices still have problems. I used only 1024x1024 atlases (bigger wouldn't work on all devices), after that problem and it never occurred again. – GameDroids Jan 31 '13 at 00:56
  • 1
    I just had a black screen too, on some devices. The reason for it was a too big texture atlas (4096*1024). But a smaller one (1024*2048) works well. – Yar Aug 26 '13 at 19:20