0

我对 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()构造函数中应用不同的值。但没有任何效果。请指导我解决这个问题。我想在横向模式下从屏幕的右边缘启动相机和场景。

4

1 回答 1

0

需要让你的相机去追逐你的玩家。您可以通过以下方式做到这一点:

camera.setChaseEntity(玩家);

只需看看 AndEngine 示例。它有一个完全满足您需求的示例。也可以通过以下链接下载代码:

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

•TMXTiledMap 示例

于 2013-08-16T06:02:43.017 回答