在“AndEngine”中移动相机安卓游戏

发布于 2024-12-28 05:40:30 字数 1001 浏览 2 评论 0原文

我正在使用 AndEngine 开发 Android 游戏。截至目前,我想在游戏中垂直移动相机。您可以想象这样的场景,类似于 Android Market 中的“Drop”游戏,其中相机不断向下移动,您使用加速度计尽可能长时间地将球保持在场景中。 https://market.android.com/details?id=com .infraredpixel.drop&hl=en

但是我在这里并没有取得太大的成功。我想不断向下移动相机,无论球的位置如何(即相机 ChaseEntity() 不起作用)。 我们将不胜感激您的帮助。我使用的是 GLES2 版本的 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);

            }

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 (i.e 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);

            }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

满天都是小星星 2025-01-04 05:40:30

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文