2

代码 :

这就是我初始化相机的方式。
我',试图获得设备的分辨率,并在此基础上设置相机的宽度和高度。

     public class GameActivity extends SimpleBaseGameActivity {

        private SmoothCamera mCamera;
        private DisplayMetrics dM; 

        private int CAMERA_WIDTH, CAMERA_HEIGHT;

        private double  ScreenWidth,
                        ScreenHeight,
                        resolutionRatio;


        public EngineOptions onCreateEngineOptions() {

             //set Camera
            getDeviceResolution();
            setCamera();


        EngineOptions options =  new EngineOptions(true,
            ScreenOrientation.LANDSCAPE_FIXED, 
            new RatioResolutionPolicy((int)this.getCameraWidth(),(int)this.getCameraHeight()),
            //new FillResolutionPolicy(),
            mCamera);
          return options;

        }

      private void getDeviceResolution() {
            dM = new DisplayMetrics();
            this.getWindowManager().getDefaultDisplay().getMetrics(dM);
            this.ScreenWidth    = dM.widthPixels;
            this.ScreenHeight   = dM.heightPixels;
            this.resolutionRatio = this.ScreenWidth/this.ScreenHeight;

                resolutionRatio = (double)Math.round(resolutionRatio * 100) / 100;

            Log.d("Resolution","ScrennWidth: "+this.ScreenWidth );
            Log.d("Resolution","ScrennHeight: "+this.ScreenHeight );
                    Log.d("Resolution","Resolution Ratio: " +   this.resolutionRatio );
        }



    private void setCamera() {

        if(resolutionRatio == 1.66){
            this.setCameraHeight(340);
            this.setCameraWidth(400);
        }else if(resolutionRatio == 2.13){
            this.setCameraHeight(480);
            this.setCameraWidth(1024);
        }else if(resolutionRatio == 1.77){
            this.setCameraHeight(720);
            this.setCameraWidth(1280);
        }else if(resolutionRatio == 1.5){
            this.setCameraHeight(320);
            this.setCameraWidth(480);
        }else if(resolutionRatio == 1.67){
            this.setCameraHeight(480);
            this.setCameraWidth(800);
        }else {
            this.setCameraHeight((int) this.ScreenHeight);
            this.setCameraWidth((int) this.ScreenWidth);
        }

        // Create a Camera
        this.mCamera = new SmoothCamera(0,0,(int)getCameraWidth(),(int)getCameraHeight(),100,100,1.0f);
            mCamera.setZoomFactor(1.0f);

            mCamera.setBoundsEnabled(true);
            mCamera.setBounds(0, 0, mCamera.getWidth(), mCamera.getHeight());   
        }



        }

问题是。

我已经在分辨率为 480x320 的设备上尝试过游戏; 在此处输入图像描述

当我在分辨率为 800X480 的设备上尝试相同的代码时在此处输入图像描述

我认为精灵没有在更高分辨率的设备上缩放。
据我所知,引擎可以原生缩放相机和精灵。

那么为什么精灵在这种情况下没有得到缩放呢?

我应该怎么做才能根据分辨率放大精灵?

我也试过 FillResolutionPolicy。一样。

我正在使用 andengine 和 SpriteSheets 的 TexturePackerExtension。

4

2 回答 2

4

你想要一个Camera固定的width和一个height由设备屏幕纵横比计算的。将其与 a 配对,FillResolutionPolicy您将得到您想要的。

笔记:

AndEngine 不会为您缩放 Sprites,但您设置 以Camera使整体Scene显示为缩放。

于 2013-04-09T06:43:04.820 回答
2

AndEngine 确实Sprites在您的示例中扩展了您的规模。结果不是您预期的原因是您设置了相机widthheight手动(基于分辨率)。

如果您真的希望每个精灵在每个显示器上都以相同的方式缩放,那么您应该选择一个固定分辨率来创建您的游戏。例如,您可以将每个精灵和每个位置设置为 960x640 的分辨率。

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

AndEngine 然后将缩放相机,使其尽可能多地填充显示。

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

1.5f是 960x640 分辨率的拟合纵横比。现在您不必再关心不同的显示尺寸了。

于 2013-04-04T20:02:26.383 回答