Scaling for Android devices with starling causing some layout issues

♀尐吖头ヾ 提交于 2019-12-10 10:54:12

问题


I'm using multi resolution technique number three as written in this article

and to determine the scale factor and stage size, I'm using this piece of code originally written by Jeff :

        if (Capabilities.screenDPI >= 200) {
            if (Capabilities.screenDPI >= 280) {
                AssetFactory.contentScaleFactor = 2;
            }
            else {
                AssetFactory.contentScaleFactor = 1.5;
            }
        }
        else {
            AssetFactory.contentScaleFactor = 1;
        }

        var mViewPort:Rectangle = new Rectangle(0, 0, stage.fullScreenWidth, stage.fullScreenHeight);

        mStarling = new Starling(Startup, stage,mViewPort);
        mStarling.stage.stageWidth = stage.fullScreenWidth /  AssetFactory.contentScaleFactor;
        mStarling.stage.stageHeight = stage.fullScreenHeight / AssetFactory.contentScaleFactor;

Then I use this scale factor to determine which sized assets I need to pick.

So now, I have a background which I strech to stage width and size. This technique works great when I'm testing with most devices but then we have devices like the Barnes and Noble Nook Color.

The device has a resolution of 600x1024 with 170 dpi. This means that it's going to pick the smallest assets (320x480) and strech it to 600x1024. Which ofcourse is pixalated. Any ideas on how to get over this issue?

I'm also attaching a test application which shows the issue in detail https://dl.dropbox.com/u/2192209/scaling%20test.zip


回答1:


What worked for me best so far is not scaling Starling's viewport at all. It should always remain the base size (320x480).

Then you have a scale factor about how big the texture should be. It's a built feature of Starling when creating a texture - passing a scale factor. What this means is that if your stage is 640x960, your scale factor will be 2. Your image (Bitmap object), will have ACTUAL SCREEN size of 320x480 (fullscreen, 1:1 with stage size), BUT it's texture (loaded asset BitmapData) will be twice as big (640x960, 1:1 with phone size).

For easier understanding - the stage of Starling (320x480) will be scaled up to fit your phone's resolution (320 -> 640). But your images will be scaled down to fit in the stage (640 -> 320). So you get perfectly normal images.

This helps you maintain fixed size of stage. It's really helpful, because otherwise it would be hard to position objects - if you want the object to be in the middle, it's sometimes 160, sometimes 320, etc. This means you always have to set position/size with calculations, which is an overload.

Hope that helps!

edit: Just remembered of a site I've used to determine my main size and assets ratios: http://screensiz.es/phone




回答2:


How about setting max scale size? If the conclusion of the calculations above takes you to scale that is grater than 2, use bigger assets to reduce the scale ratio.

Your calculation only takes screenDPI in count, try combining them with screen resolution as well.



来源:https://stackoverflow.com/questions/15542496/scaling-for-android-devices-with-starling-causing-some-layout-issues

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