AndEngine - Sprites are not getting scaled on different devices

a 夏天 提交于 2019-12-06 06:19:44

You want a Camera with a fixed width and a height that is calculated by the devices screen aspectratio. Pair that with a FillResolutionPolicy and you get what you want.

Note:

AndEngine doesn't scale Sprites for you, but you set the Camera so that the whole Scene appears scaled.

AndEngine does scale your Sprites even in your example. The reason why the result is not what you expected is that you set the camera's widthand height manually (based on the resolution).

If you really want every sprite scaled in the same way on every display, then you should choose one fixed resolution in which you create your game. For example you could set up every sprite and every position to a resolution of 960x640.

 // skip the whole if(resolutionRatio == 1.66){..  part
this.mCamera = new SmoothCamera(0, 0, 960f, 640f, 100, 100, 1.0f);

AndEngine will then scale the camera, so that it fills as much of the display as possible.

 public EngineOptions onCreateEngineOptions() {
      EngineOptions options = new EngineOptions(true, ScreenOrientation.LANDSCAPE_SENSOR, new RatioResolutionPolicy(1.5f), camera;
      return options;
 }

the 1.5f is the fitting aspect ratio for the 960x640 resolution. Now you won't have to take care of the different display sizes anymore.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!