在AS3 Mobile应用程序设置ApplicationDPI应用程序、Mobile、ApplicationDPI

2023-09-08 13:44:49 作者:浮生若梦与你相随

我在开发Flash Builder中的应用程序与AS3只(没有弯曲的东西)。在Flex可以通过以下code设置应用程序的DPI:

I developing an application in Flash Builder with AS3 only (no flex stuff). In flex it is possible to set the application's dpi by the following code:

<s:ViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
   xmlns:s="library://ns.adobe.com/flex/spark" applicationDPI="320">

不过,我只使用AS3。我已阅读,这是不可能改变应用程序的DPI在运行时(使用AS3),但我怎样才能设置此项目的设置,编译器设置或有另一种方式做到这一点?

But I using only AS3. I have read that it is not possible to change the application's DPI in run-time (with AS3), but how can I set this in project settings, compiler settings or is there another way to do it?

此外,什么是默认的应用程序的DPI设置?

Also, what is the default application's DPI setting?

问在这里,因为无法找到它在网络上(仅基于Flex的解决方案)。

Ask it here because can't find it on the net (only flex based solutions).

推荐答案

在DPI上移动由硬件设置,它完全依赖于手机和屏幕上。当您在Flex移动设置applicationDPI你告诉Flex的自动缩放你的资产。

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.

自动缩放。开发人员可以选择指定一个目标DPI通过设置applicationDPI属性上的应用程序及其应用。当此明确设置,开发者应该建立自己的外观和布局,如果他们给定的DPI的设备上运行。在运行时,如果设备有从指定的目标DPI不同的DPI时,Flex会自动缩放整个应用程序preserve应用程序及其控制的近似物理尺寸。例如,如果应用程序是针对160 DPI的,它会自动以1.5倍240 DPI设备上缩放。如果您选择不使用此功能,你需要确保你的自定义皮肤和视图布局正确适应不同的像素密度在运行时。   来源

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

在一个AS3移动项目你将需要处理这个自己。

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

您可以使用 Capabilities.screenDPI 获得当前的DPI,但我想你可能是后一个比率来扩大你的资产。这样做的一种方法是启动与原来的游戏宽度

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;

和应用给你的资产

myBitmap.scaleX = myBitmap.scaleY = ratio;

现在这是不会取装置的旋转考虑进去,所以fullScreenWidth /高度可以翻转。要检查,你将需要做这样的事情

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