在“AndEngine”中移动相机安卓游戏
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AndEngine 提供了一种更简单的方法,无需重写
onManagedUpdate
。我建议您使用
SmoothCamera
。使用流畅摄像头,你可以设置相机移动的最大速度,然后让它移动到某个地方。然后它会自动以您设置的最大速度移动到您要求的位置。只需设置 Y 速度,然后移动到某个 Y 值,并观察它缓慢(或快速,取决于您的速度)自动移向该位置。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.