Reputation: 293
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);
}
Upvotes: 3
Views: 3265
Reputation: 9115
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.
Upvotes: 5