AndEngine - 精灵没有得到缩放在不同的设备 [英] AndEngine - Sprites are not getting scaled on different devices

查看:228
本文介绍了AndEngine - 精灵没有得到缩放在不同的设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

code:

这是怎么中号初始化摄像头。

我,试图让设备的分辨率和基于我设置摄像头的宽度和高度。

This is how m initializing camera.
I', trying to get resolution of device and based on that i set camera width and height.

     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分辨率的设备etried游戏;

I've etried game on device with resolution 480x320;

,当我试图同code对设备与800X480分辨率

and when i tried same code on device with resolution 800X480

我思精灵没有得到更高分辨率的设备扩展。
按我的知识andengine扩展摄像头和精灵本身。

I Thinks sprites are not getting scaled on higher resolution devices.
As per my knowledge andengine scales camera and sprites natively.

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

So why sprites are not getting scaled on this situation?

我应该怎么做根据决议,扩大精灵?

What should i do to scale up sprites based on resolution?

我试过FillResolutionPolicy了。同样的事情。

I tried FillResolutionPolicy too. Same thing.

我使用andengine ADN SpriteSheets的TexturePackerExtension。

I'm using TexturePackerExtension of andengine adn SpriteSheets.

推荐答案

您希望有一个相机以固定宽度高度由该设备屏幕ASPECTRATIO计算。一对以 FillResolutionPolicy ,你会得到你想要的。

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.

请注意:

AndEngine没有的比例精灵你,但你设置的相机使整个场景出现缩放。

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

这篇关于AndEngine - 精灵没有得到缩放在不同的设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆