Detect Screen Resolution


Detect the native resolution of the device and use for screen and camera.


Depending on type of application might not be advisable to do. You cant use hardcoded locations for sprites or other objects, rather calculate in relation to detected screensize. Also, AndEngine scales the image quite well so often it will not be necessary to render in the exact resolution of the device.


public Engine onLoadEngine() {
    final Display display = getWindowManager().getDefaultDisplay();
    int cameraWidth = display.getWidth();
    int cameraHeight = display.getHeight();
    String deb = String.format("Screen: %d / %d",cameraWidth,cameraHeight);
    Log.d("Debug:", deb);
    this.mCamera = new Camera(0, 0, cameraWidth,cameraHeight);
    return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, 
        new RatioResolutionPolicy(cameraWidth, cameraHeight), this.mCamera));


Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License