2012-11-05 3 views
1

Je suis un développement de noob android et j'essaie d'apprendre à utiliser AndEngine. Je veux construire une scène où un sprite apparait derrière un objet au premier plan, puis disparaît d'une manière whack-a-mole. J'ai passé en revue chaque projet d'exemple mais ne peux pas trouver n'importe quel code qui montre comment faire ceci. Toute aide est grandement appréciée.Comment créer des scènes multi-couches avec AndEngine?

Actuellement, j'essaie d'utiliser une image-objet pour définir la scène de premier plan en vain.

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

Répondre

5

Si je comprends bien, vous avez besoin de couches .. Vous pouvez utiliser des entités comme des couches:

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

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

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

J'espère que cela vous aidera.

+0

Merci Racoon :-) – Kalpesh

Questions connexes