2012-11-05 23 views
1

我是Android開發的小菜鳥,我正在嘗試學習如何使用AndEngine。我想要構建一個場景,其中精靈從前景中的對象後面出現,然後以鼴鼠的方式消失。我已經回顧了每個示例項目,但找不到任何代碼顯示如何執行此操作。任何幫助是極大的讚賞。如何使用AndEngine構建多層場景?

目前,我正在嘗試使用精靈設置前景場景無濟於事。

@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; 
    } 

回答

5

如果我理解正確的話,你需要層.. 您可以使用實體層:

Entity backgroundLayer = new Entity(); 
backgroundLayer.attachChild(face); 

Entity foregroundLayer= new Entity(); 
foregroundLayer.attach(foreground); 

scene.attachChild(backgroundLayer); 
scene.attachChild(foregroundLayer); 

我希望這會幫助你。

+0

謝謝浣熊:-) – Kalpesh