Detect Screen Resolution

Function

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

Remarks

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.

Snippet

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));
}

(Source: http://www.andengine.org/forums/development/a-new-andengine-user-t1915.html?sid=66680497de7463e77a97e0edfa19990b#p9406)

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