每个人。 我正在使用 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/