简体   繁体   中英

Moving Camera in 'AndEngine' Game for Android

Im developing a game for Android using AndEngine. As of now, I want to move the camera vertically in my game. You can imagine the scenario that to similar of the "Drop" game available in Android Market, where the camera is constantly moving down and you use the accelerometer to keep the ball in the scene as long as you can. https://market.android.com/details?id=com.infraredpixel.drop&hl=en )

However I haven't been able to achieve much success here. I want to move the camera down constantly regardless of the position of the ball (ie camera ChaseEntity() will not work). Your help will be appreciated. Im using the GLES2 version of AndEngine

private static final int CAMERA_WIDTH = 720;
private static final int CAMERA_HEIGHT = 480;
private Camera mCamera;


public Engine onLoadEngine() {

            this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);

            return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE,new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera));

    }

protected void onManagedUpdate(final float pSecondsElapsed) {

                    //Move camera down 
                    super.onManagedUpdate(pSecondsElapsed);

            }

There's an easier method that AndEngine provides, without needing to override onManagedUpdate .

I suggest you to use a SmoothCamera . Using a smooth camera , you can set the maximum velocity for the camera to move at, then ask it to move somewhere. It will then automatically move at the maximum velocity you set toward the position you asked. Just set the Y velocity then move to some Y value and watch as it slowly (Or fast, depending on your velocity) moves toward the position automatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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