如何构建多层次的场景与AndEngine? [英] How Do I Build Multi-Layered Scenes with AndEngine?

查看:134
本文介绍了如何构建多层次的场景与AndEngine?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个小白Android开发,我想学习如何使用AndEngine。我想,其中一个精灵从前景对象背后出现,然后在捶痣消失的方式来构建一个场景。我查看了每一个示例项目,但找不到任何code,显示如何做到这一点。任何帮助是极大的AP preciated。

目前,我试图用一个精灵到前台的场景设置无济于事。

  @覆盖
    公共场景onCreateScene(){
        this.mEngine.registerUpdateHandler(新FPSLogger());        最后一幕一幕=新场景();
        最终AutoParallaxBackground autoParallaxBackground =新AutoParallaxBackground(0,0,0,5);
        最终VertexBufferObjectManager vertexBufferObjectManager = this.getVertexBufferObjectManager();
        autoParallaxBackground.attachParallaxEntity(新ParallaxEntity(0.0,新的Sprite(0,CAMERA_HEIGHT - this.mParallaxLayerBack.getHeight(),this.mParallaxLayerBack,vertexBufferObjectManager)));
        autoParallaxBackground.attachParallaxEntity(新ParallaxEntity(-5.0f,新的Sprite(0,80,this.mParallaxLayerMid,vertexBufferObjectManager)));
        autoParallaxBackground.attachParallaxEntity(新ParallaxEntity(-10.0f,新的Sprite(0,CAMERA_HEIGHT - this.mParallaxLayerFront.getHeight(),this.mParallaxLayerFront,vertexBufferObjectManager)));
        scene.setBackground(autoParallaxBackground);        最终浮动的centerX =(CAMERA_WIDTH - this.mFaceTextureRegion.getWidth())/ 2;
        最终浮动centerY =(CAMERA_HEIGHT - this.mFaceTextureRegion.getHeight())/ 2;
        最后面对雪碧=新的雪碧(的centerX,centerY,this.mFaceTextureRegion,this.getVertexBufferObjectManager());
        最后PhysicsHandler physicsHandler =新PhysicsHandler(面);
        face.registerUpdateHandler(physicsHandler);        scene.attachChild(面);        最后雪碧前景=新的雪碧(的centerX,centerY,this.mFaceTextureRegion2,this.getVertexBufferObjectManager());
        最后PhysicsHandler physicsHandler2 =新PhysicsHandler(前景);
        face.registerUpdateHandler(physicsHandler2);        scene.setChildScene(前景); //< - 给我的错误
    返回现场;
    }


解决方案

如果我理解正确的话,你需要层..
您可以使用实体层:

 实体backgroundLayer =新实体();
backgroundLayer.attachChild(面);实体foregroundLayer =新实体();
foregroundLayer.attach(前景);scene.attachChild(backgroundLayer);
scene.attachChild(foregroundLayer);

我希望这会帮助你。

I am a noob to android development and i am trying to learn how to use AndEngine. I want to construct a scene where a sprite appears from behind an object in the foreground and then disappears in a whack-a-mole fashion. I've reviewed every example project but can't find anything code that shows how to do this. any help is greatly appreciated.

Currently, I am trying to use a sprite to set the foreground scene to no avail.

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

解决方案

If I understood correctly, you need layers.. You can use entities as layers:

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

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

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

I hope this will help you.

这篇关于如何构建多层次的场景与AndEngine?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆