如何在AndEngine GLES1.0中更改场景/摄像机起始位置

时间:2013-08-16 05:54:42

标签: android camera andengine scene

我对AndEngine相对较新,并陷入了一个问题。 我做了一个真正的示例演示游戏,其中角色可以在由Tiled制作的游戏中左右移动。默认情况下,当游戏开始时,场景/摄像机和角色位于屏幕的左侧。在横向模式下,相机从屏幕的左边缘移动到右侧。 以下是我的工作代码:

private BoundCamera mCamera;
@Override
    public Engine onLoadEngine() {

        this.mCamera = new BoundCamera(-100, -100, CAMERA_WIDTH, CAMERA_HEIGHT){
            @Override
            public void onApplySceneMatrix(GL10 pGL) {
                    GLHelper.setProjectionIdentityMatrix(pGL);

                    GLU.gluOrtho2D(pGL, (int)this.getMinX(), (int)this.getMaxX(), (int)this.getMaxY(), (int)this.getMinY());
            }

        };

        final EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT),
                mCamera);
        engineOptions.getTouchOptions().setRunOnUpdateThread(true);
        engineOptions.setNeedsMusic(true).setNeedsSound(true);

        // It is necessary in a lot of applications to define the following
        // wake lock options in order to disable the device's display
        // from turning off during gameplay due to inactivity
        engineOptions.setWakeLockOptions(WakeLockOptions.SCREEN_ON);

        final Engine engine = new Engine(engineOptions);

        try {
            if (MultiTouch.isSupported(this)) {
                engine.setTouchController(new MultiTouchController());
                if (MultiTouch.isSupportedDistinct(this)) {

                } else {
                    Toast.makeText(this, "(MultiTouch detected, but your device might have problems to distinguish between separate fingers.)",
                            Toast.LENGTH_LONG).show();
                }
            } else {
                Toast.makeText(this, "Sorry your device does NOT support MultiTouch!\n\n(Falling back to SingleTouch.)", Toast.LENGTH_LONG).show();
            }
        } catch (final MultiTouchException e) {
            Toast.makeText(this, "Sorry your Android Version does NOT support MultiTouch!\n\n(Falling back to SingleTouch.)", Toast.LENGTH_LONG).show();
        }

        return engine;
    }

我尝试在new BoundCamera()构造函数中应用不同的值。但没有任何作用。 请指导我解决这个问题。我想在横向模式下从屏幕右边缘开始摄像机和场景。

1 个答案:

答案 0 :(得分:0)

需要让相机追逐你的播放器。您可以通过以下方式执行此操作:

camera.setChaseEntity(播放器);

看看AndEngine示例。它有一个完全符合您需求的例子。请点击以下链接下载代码:

http://code.google.com/p/andengineexamples/

•TMXTiledMapExample

相关问题