java - 将 Sprite 隐藏在 AutoParallax Background Andengine 后面

标签 java android parent-child andengine

每个人。 我正在使用 Andengine 制作 Android 游戏。 我在这个游戏中使用自动视差背景。现在我想在屏幕上添加一个 Sprite ,使视差背景出现在 Sprite 前面。然而,当 Sprite 覆盖背景时,它并不像我预期的那样

这是我的代码

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);

}

我要隐藏的 Sprite 是

rock

背景是

ground

我能做什么?任何帮助,将不胜感激。 提前致谢

最佳答案

如果你想让岩石保持在背景之间,尝试使用 autoParallaxBackground,放置 Sprite 并将岩石的速度设置为 0,我认为是这样的:

    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);

希望对您有所帮助!

关于java - 将 Sprite 隐藏在 AutoParallax Background Andengine 后面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26959442/

相关文章:

java - Hibernate:父实体上的过滤器是否隐式过滤子实体?

java - Android ListView 未在滚动时重新绘制

java - 在 Java 中持久化对象的轻量级方法

Android 教程 "Create the second activity"不适用于 Android Studio,或者

android - 模拟器在android studio最新版本中不起作用

c# - 通过句柄或 pid 获取窗口的子窗口

java - 使用 xmlbeans 创建并填充 xml 文档

java - 如何在用户界面(Primefaces)上显示 java List<Object>

java - Android searchview 删除提示填充

data-structures - 如何为具有多个父项的数据实体建模?