I’m new to AndEngine and I’m trying to implement hanoi game following this tutorial.
After inserting the background image to the gfx folder, and setting up all onCreateResources code and onCreateScene code, I tried to run the app, and all I can see is a triangle representing my background image, as you can see in this image.

Here is the my code:
final int CAMERA_WIDTH = 480;
final int CAMERA_HEIGHT = 800;
public EngineOptions onCreateEngineOptions() {
myCamera = new Camera(800, 480, CAMERA_WIDTH, CAMERA_HEIGHT);
return new EngineOptions(false, ScreenOrientation.PORTRAIT_SENSOR,
new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT),
myCamera);
}
public ITextureRegion texture;
public void onCreateResources(
OnCreateResourcesCallback pOnCreateResourcesCallback)
throws Exception {
try {
// 1 - Set up bitmap textures
ITexture backgroundTexture = new BitmapTexture(
this.getTextureManager(), new IInputStreamOpener() {
public InputStream open() throws IOException {
return getAssets().open("gfx/background.png");
}
});
// 2 - Load bitmap textures into VRAM
backgroundTexture.load();
// 3 - Set up texture regions
this.mBackgroundTextureRegion = TextureRegionFactory
.extractFromTexture(backgroundTexture);
}
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback)
throws Exception {
// 1 - Create new scene
final Scene scene = new Scene();
Sprite backgroundSprite = new Sprite(0, 0, this.mBackgroundTextureRegion, getVertexBufferObjectManager());
scene.attachChild(backgroundSprite);
}
Since I’ve tried to solve this error on my own, I’ve already tried:
- setting the camera FillResolutionPolicy(), with no effect on the outcome.
- Create the background as a BitmapTextureAtlas, BitmapTextureAtlasTextureRegionFactory.createFromAsset
- calling mEngine.getScene().setBackground instead of attachChild
- Recreate the Android virtual device with another API levels (tried 16, 15)
Also, there’s a thread in the AndEngine forum, this one in which I didn’t find my answer.
You have some mistakes in your code
1) In
myCamera = new Camera(800, 480, CAMERA_WIDTH, CAMERA_HEIGHT);first and second argument is for position x and y. So you should do like
2) In CameraOptions use
3) To load a BitmapTexture you should use
BitmapTextureAtlasTextureRegionFactoryfor example.