Авто параллакс фон в Анденжине - PullRequest
0 голосов
/ 15 марта 2012

Как мне создать фон параллакса в AndEngine, который сливается спереди и расширяется снизу?

Есть способ сделать это, но я что-то упускаю ... Мой фон параллакса работаетхорошо, но оно не сливается от начала до конца.

Ответы [ 2 ]

0 голосов
/ 17 сентября 2014

Я использую это для полного экрана

autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(0.0f, new Sprite(0, 0, camera.getWidth() ,camera.getHeight() ,this.mParallaxLayerBack, vertexBufferObjectManager)));
    autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-5.0f, new Sprite(0, 80, this.mParallaxLayerMid, vertexBufferObjectManager)));
    autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-10.0f, new Sprite(0, cameraHeight - this.mParallaxLayerFront.getHeight(), this.mParallaxLayerFront, vertexBufferObjectManager)));
    scene.setBackground(autoParallaxBackground);

обратите внимание, что камера - это глобальная переменная, надеюсь, это поможет вам!

0 голосов
/ 16 марта 2012
@Override
public void onLoadResources() {
    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");

    this.mBitmapTextureAtlas = new BitmapTextureAtlas(256, 128, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
    this.mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mBitmapTextureAtlas, this, "player.png", 0, 0, 3, 4);
    this.mEnemyTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mBitmapTextureAtlas, this, "enemy.png", 73, 0, 3, 4);

    this.mAutoParallaxBackgroundTexture = new BitmapTextureAtlas(1024, 1024, TextureOptions.DEFAULT);
    this.mParallaxLayerFront = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAutoParallaxBackgroundTexture, this, "parallax_background_layer_front.png", 0, 0);
    this.mParallaxLayerBack = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAutoParallaxBackgroundTexture, this, "parallax_background_layer_back.png", 0, 188);
    this.mParallaxLayerMid = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mAutoParallaxBackgroundTexture, this, "parallax_background_layer_mid.png", 0, 669);

    this.mEngine.getTextureManager().loadTextures(this.mBitmapTextureAtlas, this.mAutoParallaxBackgroundTexture);
}

@Override
public Scene onLoadScene() {
    this.mEngine.registerUpdateHandler(new FPSLogger());

    final Scene scene = new Scene();
    final AutoParallaxBackground autoParallaxBackground = new AutoParallaxBackground(0, 0, 0, 5);
    autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(0.0f, new Sprite(0, CAMERA_HEIGHT - this.mParallaxLayerBack.getHeight(), this.mParallaxLayerBack)));
    autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-5.0f, new Sprite(0, 80, this.mParallaxLayerMid)));
    autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-10.0f, new Sprite(0, CAMERA_HEIGHT - this.mParallaxLayerFront.getHeight(), this.mParallaxLayerFront)));
    scene.setBackground(autoParallaxBackground);

    /* Calculate the coordinates for the face, so its centered on the camera. */
    final int playerX = (CAMERA_WIDTH - this.mPlayerTextureRegion.getTileWidth()) / 2;
    final int playerY = CAMERA_HEIGHT - this.mPlayerTextureRegion.getTileHeight() - 5;

    /* Create two sprits and add it to the scene. */
    final AnimatedSprite player = new AnimatedSprite(playerX, playerY, this.mPlayerTextureRegion);
    player.setScaleCenterY(this.mPlayerTextureRegion.getTileHeight());
    player.setScale(2);
    player.animate(new long[]{200, 200, 200}, 3, 5, true);

    final AnimatedSprite enemy = new AnimatedSprite(playerX - 80, playerY, this.mEnemyTextureRegion);
    enemy.setScaleCenterY(this.mEnemyTextureRegion.getTileHeight());
    enemy.setScale(2);
    enemy.animate(new long[]{200, 200, 200}, 3, 5, true);

    scene.attachChild(player);
    scene.attachChild(enemy);

    return scene;
}

@Override
public void onLoadComplete() {

}

}

...