我是Android开发的菜鸟,我正在尝试学习如何使用AndEngine。我想构建一个场景,其中一个精灵从前景中的一个物体后面出现,然后以一种w mole的方式消失。我已经审查了每个示例项目,但找不到任何显示如何执行此操作的代码。任何帮助是极大的赞赏。
目前,我正在尝试使用精灵来设置前景场景无济于事。
@Override
public Scene onCreateScene() {
this.mEngine.registerUpdateHandler(new FPSLogger());
final Scene scene = new Scene();
final AutoParallaxBackground autoParallaxBackground = new AutoParallaxBackground(0, 0, 0, 5);
final VertexBufferObjectManager vertexBufferObjectManager = this.getVertexBufferObjectManager();
autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(0.0f, new Sprite(0, CAMERA_HEIGHT - this.mParallaxLayerBack.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, CAMERA_HEIGHT - this.mParallaxLayerFront.getHeight(), this.mParallaxLayerFront, vertexBufferObjectManager)));
scene.setBackground(autoParallaxBackground);
final float centerX = (CAMERA_WIDTH - this.mFaceTextureRegion.getWidth()) / 2;
final float centerY = (CAMERA_HEIGHT - this.mFaceTextureRegion.getHeight()) / 2;
final Sprite face = new Sprite(centerX, centerY, this.mFaceTextureRegion, this.getVertexBufferObjectManager());
final PhysicsHandler physicsHandler = new PhysicsHandler(face);
face.registerUpdateHandler(physicsHandler);
scene.attachChild(face);
final Sprite foreground = new Sprite(centerX, centerY, this.mFaceTextureRegion2, this.getVertexBufferObjectManager());
final PhysicsHandler physicsHandler2 = new PhysicsHandler(foreground);
face.registerUpdateHandler(physicsHandler2);
scene.setChildScene(foreground); //<--Gives me error
return scene;
}
答案 0 :(得分:5)
如果我理解正确,你需要图层.. 您可以将实体用作图层:
Entity backgroundLayer = new Entity();
backgroundLayer.attachChild(face);
Entity foregroundLayer= new Entity();
foregroundLayer.attach(foreground);
scene.attachChild(backgroundLayer);
scene.attachChild(foregroundLayer);
我希望这会对你有所帮助。