简体   繁体   中英

Hide Sprite behind AutoParallax Background Andengine

Everyone. I'm making an Android game with Andengine. I use Autoparallax background in this game. Now I want to add a sprite to the screen in such a way that the parallax background will appear in front of the sprite. However, it is not as I expected when the sprite coverd the background

This is my code

public static void populateSplashScene(Engine pEngine) {

// create and attach ground to splash scene
MainActivity.ground = new Sprite(0, 0,
    mSpritesheetTextureRegionLibrary
        .get(TextureRegionId.GROUNDGRASS_ID),
    pEngine.getVertexBufferObjectManager());
MainActivity.ground.setOffsetCenter(0, 0);
MainActivity.background.attachParallaxEntity(new ParallaxEntity(-3,
    MainActivity.ground));

// create and attach rock to splash scene
MainActivity.rock = new Sprite(0, 0,
    mSpritesheetTextureRegionLibrary
        .get(TextureRegionId.ROCKGRASS_ID),
    pEngine.getVertexBufferObjectManager());
MainActivity.rock.setOffsetCenter(0, 0);
MainActivity.ground.attachChild(MainActivity.rock);

// create and attach rockDown to splashscene
MainActivity.rockDown = new Sprite(30, MainActivity.CAMERA_HEIGHT,
    mSpritesheetTextureRegionLibrary
        .get(TextureRegionId.ROCKGRASSDOWN_ID),
    pEngine.getVertexBufferObjectManager());
MainActivity.rockDown.setOffsetCenter(0, 1);
MainActivity.ground.attachChild(MainActivity.rockDown)

PhysicsHandler physicsHandler = new PhysicsHandler(MainActivity.ground);
MainActivity.ground.registerUpdateHandler(physicsHandler);
physicsHandler.setVelocityX(-25);

}

the sprite which I want to hide is

rock

the background is

ground

What can I do? Any help would be appreciated. Thank in advance

if you want to keep the rock between background, try use autoParallaxBackground, put the sprites and set the speed to 0 for the rock, i think something like this:

    autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(0f,
        new Sprite(posX,posY,activity.getmParallaxRock(),vertexBufferObjectManager)));

    autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-10.0f,
        new Sprite(posX, posY,activity.getmParallaxGround(),VertexBufferObjectManager)));

    setBackground(autoParallaxBackground);

Hope it can help!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM