0

I'm building a live wallpaper with Andengine and I am having troubles starting it off. I cannot seem to get a parallexing background working. The end result of my code results in the assets upsidedown on the top right of the screen.

public class WallpaperService extends BaseLiveWallpaperService {

private static final int CAMERA_WIDTH = 800;
private static final int CAMERA_HEIGHT = 480;

private static final String BG_FOREGROUND = "background/arctic_foreground.png";
private static final String BG_MIDGROUND  = "background/arctic_midground.png";
private static final String BG_BACKGROUND = "background/arctic_land.png";

private static final int BG_TEXTURE_ATLAS_HEIGHT_WIDTH = 2048;
private static final int BG_FOREGROUND_START_HEIGHT = 0;
private static final int BG_MIDGROUND_START_HEIGHT = 600;
private static final int BG_BACKGROUND_START_HEIGHT = 1200;

private Camera camera;
private BitmapTextureAtlas backgroundTexture;
private TextureManager textureManager;
private TextureRegion mParallaxLayerFront;
private TextureRegion mParallaxLayerBack;
private TextureRegion mParallaxLayerMid;

@Override
public EngineOptions onCreateEngineOptions() {
    camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
    EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new FillResolutionPolicy(), this.camera);
    engineOptions.setWakeLockOptions(WakeLockOptions.SCREEN_ON);
    textureManager = new TextureManager();
    return engineOptions;
}

@Override
public void onCreateResources(OnCreateResourcesCallback pOnCreateResourcesCallback) throws Exception {
    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");

    this.backgroundTexture = new BitmapTextureAtlas(textureManager, BG_TEXTURE_ATLAS_HEIGHT_WIDTH, BG_TEXTURE_ATLAS_HEIGHT_WIDTH, TextureOptions.DEFAULT);
    this.mParallaxLayerFront = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.backgroundTexture, this, BG_FOREGROUND, 0, BG_FOREGROUND_START_HEIGHT);
    this.mParallaxLayerBack = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.backgroundTexture, this, BG_BACKGROUND, 0, BG_MIDGROUND_START_HEIGHT);
    this.mParallaxLayerMid = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.backgroundTexture, this, BG_MIDGROUND, 0, BG_BACKGROUND_START_HEIGHT);

    this.mEngine.getTextureManager().loadTexture(this.backgroundTexture);
}

@Override
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws Exception {
    final Scene scene = new Scene();
    final AutoParallaxBackground autoParallaxBackground = new AutoParallaxBackground(0, 0, 0, 0);
    autoParallaxBackground.attachParallaxEntity(new ParallaxBackground.ParallaxEntity(0.0f,
            new Sprite(0, 0, this.mParallaxLayerBack, getVertexBufferObjectManager())));

    autoParallaxBackground.attachParallaxEntity(new ParallaxBackground.ParallaxEntity(0.0f,
            new Sprite(0, 0, this.mParallaxLayerMid, getVertexBufferObjectManager())));

    autoParallaxBackground.attachParallaxEntity(new ParallaxBackground.ParallaxEntity(0.0f,
            new Sprite(0, 0, this.mParallaxLayerFront, getVertexBufferObjectManager())));

    scene.setBackground(autoParallaxBackground);
    pOnCreateSceneCallback.onCreateSceneFinished(scene);
}

@Override
public void onPopulateScene(Scene pScene, OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception {
    pOnPopulateSceneCallback.onPopulateSceneFinished();
}

Result

Any help is greatly appreciated

Darussian
  • 1,573
  • 1
  • 16
  • 28

1 Answers1

0

All the images have 600 px of heigth? the problem seems to be that the images are collapsing with each other.

Maybe the problem is here:

autoParallaxBackground.attachParallaxEntity(
    new ParallaxBackground.ParallaxEntity(0.0f,
        new Sprite(0, 0, this.mParallaxLayerBack, getVertexBufferObjectManager())));

try to use this code:

autoParallaxBackground.attachParallaxEntity(new ParallaxBackground.ParallaxEntity(0.0f,
     new Sprite(0, CAMERA_HEIGHT- this.mParallaxLayerBack.getHeight(),
                this.mParallaxLayerBack, getVertexBufferObjectManager())));

i hope this will help you!

Pino
  • 7,468
  • 6
  • 50
  • 69
El0din
  • 3,208
  • 3
  • 20
  • 31