We can determine screen resolution of different android devices (phone and tablets) programmatically in andengine and set camera width and height easily by adding the following code snippet
public Engine onLoadEngine() {
WindowManager w = getWindowManager();
Display d = w.getDefaultDisplay();
//d.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
DisplayMetrics metrics = new DisplayMetrics();
d.getMetrics(metrics);
CAMERA_WIDTH = d.getWidth();
CAMERA_HEIGHT = d.getHeight();
final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera));
}
public Engine onLoadEngine() {
WindowManager w = getWindowManager();
Display d = w.getDefaultDisplay();
//d.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
DisplayMetrics metrics = new DisplayMetrics();
d.getMetrics(metrics);
CAMERA_WIDTH = d.getWidth();
CAMERA_HEIGHT = d.getHeight();
final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera));
}
0 comments