【问题标题】:Hide Sprite behind AutoParallax Background Andengine在 AutoParallax 背景和引擎后面隐藏 Sprite
【发布时间】:2023-03-09 06:18:01
【问题描述】:

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

这是我的代码

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

}

我要隐藏的精灵是

rock

背景是

ground

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

【问题讨论】:

  • 你只是想用'ground'(背景')隐藏'rock'?
  • 背景是我的自动视差背景,地面是它的孩子。现在我想在背景和地面之间保持岩石,但我没有办法做到这一点。
  • 看不懂,能不能发个图什么的再解释一下?

标签: java android parent-child andengine


【解决方案1】:

如果你想在背景之间保持岩石,请尝试使用 autoParallaxBackground,放置精灵并将岩石的速度设置为 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);

希望对你有帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-07
    • 1970-01-01
    相关资源
    最近更新 更多