问题
I'm starting with AndEngine following this tutorial:
http://www.matim-dev.com/full-game-tutorial---part-1.html
But this guy looks like it's using a low resolution device for this test, I'm using a Galaxy S4 with a 1920x1080 resolution, yeah, damn high.
I know the thing about the RatioResolutionPolicy, but even though I'm using 800x480 in my S4 I got 2 white stripes from both sides (LANDSCAPE) like if it wasn't good resized, do I need to include another wallpaper for very high screen resolution devices?
Also, some coordinates that this guy used on the tutorial are bad placed on my S4, How am I supposed to make all devices compatible with this?
ADDING CODE:
private static int CAMERA_WIDTH = 800;
private static int CAMERA_HEIGHT = 480;
@Override
public EngineOptions onCreateEngineOptions() {
camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.camera);
engineOptions.getAudioOptions().setNeedsMusic(true).setNeedsSound(true);
engineOptions.setWakeLockOptions(WakeLockOptions.SCREEN_ON);
return engineOptions;
}
回答1:
Your problem is not the resolution, but the ratio. your camera has a ratio of 1.66, while your device has a ratio of 1.77, that is almost the same, but not the same.
You Need to calculate the ratio. Andengine will project the camera in any device, that's the magic of opengl and the camera, but if the ratio is not the same, it has to put that lines to avoid the image to be cropped or distorted, like when you see a 4:3 movie in a 16:9 tv
The solution would be to have a camera that has the same ratio has the device, so if the ratio is different, you dont have white stripes, but for example some extra background.
For example, in your case, you get the device size, get the ratio (1920/1080=1.7777) so you create a camera with that ratio. ie:
float device_ratio = DEVICE_HEIGHT/DEVICE_WIDTH;// in this case 1.7777
CAMERA_WIDTH = 800;
CAMERA_HEIGHT = 800/device_ratio ; /// this will be 450
So, you will have a camera of 800x450, and you can have backgrounds of that size (or some bigger that you can crop). This is, you don't have to use images of the full size of the device, but just create a camera of the same size of the device, and create backgrounds that look ok in that camera. You create your world in that 800x450 "canvas", and andengine will project it in the real device. Since the ratio is the same, everything will look ok. nothing cropped, nothing distorted, and no extra lines.
Now you has to think in a more relative way, since your camera will not be always be exactly the same, depending on the device. This is straightforward if you don't have many hardcoded values.
来源:https://stackoverflow.com/questions/20963751/how-to-handle-galaxy-s4-resolution-since-its-too-high-for-andengine-ratioresolu