Set ApplicationDPI in AS3 Mobile application

左心房为你撑大大i 提交于 2019-12-04 14:46:52

The DPI on mobile is set by the hardware, it is entirely dependent on the phone and screen. When you set the applicationDPI in a Flex mobile you're telling Flex to automatically scale your assets.

Automatic scaling. Developers can choose to specify a target DPI for their application by setting the applicationDPI property on the application. When this is explicitly set, developers should set up their skins and layout as if they were running on a device of the given DPI. At runtime, if the device has a different DPI from the specified target DPI, Flex will automatically scale the entire application to preserve the approximate physical size of the application and its controls. For example, if an application is targeted at 160 DPI, it will automatically scale by 1.5x on a 240 DPI device. If you choose not to use this feature, you'll need to make sure your custom skins and view layouts adapt properly to different pixel densities at runtime. Source

In an AS3 mobile project you're going to need to handle this yourself.

You can get the current DPI using Capabilities.screenDPI but I think what you may be after is a ratio to scale your assets by. One way to do this would be to start with the original game width.

 private static const WIDTH:Number = 1024;

You can then get a ratio using

 var ratio:Number = stage.fullScreenWidth / WIDTH;

And apply this to your assets

myBitmap.scaleX = myBitmap.scaleY = ratio;

Now this isn't going to take the rotation of the device into account, so fullScreenWidth/Height may be flipped. To check for that you're going to need to do something like this

if (stage.fullScreenWidth > stage.fullScreenHeight){
  //portrait 
} else {
  //landscape
}

Hopefully this helps

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