简体   繁体   English

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

[英]How to change Scene / Camera starting position in AndEngine GLES1.0

I am relatively new to AndEngine and stuck in one problem. 我对AndEngine比较陌生,陷入一个问题。 I made a really sample demo game, in which the character can move left and right in a game made of Tiled. 我制作了一个真正的示例游戏,其中角色可以在Tiled制成的游戏中左右移动。 By default, when the game starts, the scene/camera and character is placed at the left side of the screen. 默认情况下,当游戏开始时,场景/摄像机和角色将放置在屏幕的左侧。 The camera moves from left edge of the screen to right side in Landscape mode. 在横向模式下,相机从屏幕的左边缘移动到右侧。 Below is my working code: 下面是我的工作代码:

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

I tried apply different values in new BoundCamera() constructor. 我尝试在new BoundCamera()构造函数中应用不同的值。 But nothing works. 但是没有任何效果。 Please guide me to solve this. 请指导我解决这个问题。 I want to start the camera and scene from the right edge of the screen in Landscape mode. 我想在横向模式下从屏幕的右边缘启动相机和场景。

In need to make your camera to chase your player. 需要使您的相机追逐您的播放器。 You can do this by: 您可以通过以下方式做到这一点:

camera.setChaseEntity(player); camera.setChaseEntity(player);

Just have a look at AndEngine Examples. 只需看看AndEngine示例。 It has an example which exactly serves your need. 它有一个完全满足您需求的示例。 Follow the link below to download the code as well: 请点击下面的链接下载代码:

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

•TMXTiledMapExample •TMXTiledMapExample

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM