简体   繁体   English

我的Flash应用程序如何在所有Android设备中正确匹配?

[英]How can my flash app fit correctly in all Android devices?

I am making a Flash game for Android devices. 我正在为Android设备制作Flash游戏。 I made my game to fit the dimensions of an HTC EVO 4G, but when I play it on a different device such as a Motorola Droid 2 with different dimensions; 我让我的游戏符合HTC EVO 4G的尺寸,但是当我在不同的设备上播放时,例如具有不同尺寸的摩托罗拉Droid 2; it does not fill up the whole screen. 它没有填满整个屏幕。 How do I make it so that my flash game fits the screen correctly of all Android devices? 如何使我的Flash游戏适合所有Android设备的屏幕?

You need to avoid using absolute numbers. 您需要避免使用绝对数字。 So instead of setting your game to run at 800px in width, you make it run at stage.stageWidth and you use resize functions (add an Event.RESIZE listener to stage ) to make sure everything fits within that. 因此,不要将游戏设置为以800px宽度运行,而是让它在stage.stageWidth运行,并使用resize函数(将Event.RESIZE侦听器添加到stage )以确保所有内容都适合Event.RESIZE The idea is to completely eliminate any hard values. 这个想法是完全消除任何硬性价值。 Everything should be relative. 一切都应该是相对的。

You should also avoid setting the stage size on mobile devices entirely. 您还应该避免完全在移动设备上设置舞台大小。 I cannot remember if that will even work in AIR, honestly. 我不记得这是否真的可以在AIR中使用。 Avoid setting stage size, and avoid setting stage.scaleMode too 避免设置舞台大小,并避免设置stage.scaleMode

So you want to center something? 所以你想要集中精力? On the 800px screen, you may have set the x value to 450px for a 100px wide object. 在800px屏幕上,您可能已将100px宽对象的x值设置为450px。 Now, you need to set it to (stage.stageWidth - object.width ) / 2 . 现在,您需要将其设置为(stage.stageWidth - object.width ) / 2 Things like that. 像这样的东西。 My guess is you will have to rewrite a significant portion of your game to do this. 我的猜测是你必须重写你游戏的重要部分才能做到这一点。

It's also worth noting that your assets are likely too small for higher-resolution screens. 值得注意的是,对于分辨率更高的屏幕,您的资产可能太小。 The EVO 4G was just 217 dpi. EVO 4G只有217 dpi。 Nowadays, there isn't a high-end phone out there lower than 320 dpi (the iPhone) with many in the mid-400's. 如今,没有高端手机低于320 dpi(iPhone),其中有许多在400年代中期。 Android currently supports as high as 680 dpi, I believe. 我相信Android目前支持高达680 dpi。

Long story short, if you are programming for a single screen size, you are doing it completely wrong. 简而言之,如果你是针对单个屏幕尺寸进行编程,那么你完全错了。 Everything you do, no matter what device or platform or os or technology, should be screen-independent at this point. 您所做的一切,无论是什么设备或平台,操作系统或技术,都应该与屏幕无关。

There may be an easier way to do this but you can listen for the Resize event which will give you the correct stage size for the device you are on. 可能有一种更简单的方法可以执行此操作,但您可以侦听Resize事件,该事件将为您提供正确的舞台大小。 Once it has been fired, you can calculate the your new scale factor based on the new size then apply that scaling to your display objects. 触发后,您可以根据新的大小计算新的比例因子,然后将该比例应用于显示对象。 The 800 x 480 is just going to be whatever resolution you are targeting to being with, you can make constants for these values. 800 x 480只是您要使用的任何分辨率,您可以为这些值制作常量。 I've tried it and it works but like I said there may be an easier way. 我已经尝试了它并且它有效,但就像我说的那样可能有一种更简单的方法。

public class MyApp extends Sprite
{

    public static var _scaleFactorX:Number = 1.0;
    public static var _scaleFactorY:Number = 1.0;

    public function MyApp ()
    {
        super();

        // support autoOrients
        stage.align = StageAlign.TOP_LEFT;
        stage.scaleMode = StageScaleMode.NO_SCALE;

        this.stage.addEventListener(flash.events.Event.RESIZE, resize);
    }

    public function init():void
    {
        // Set up our scale factor
        _scaleFactorX = this.stage.stageWidth / 800;
        _scaleFactorY = this.stage.stageHeight / 480;
    }

    protected function resize(event:Event):void
    {
        this.stage.removeEventListener(flash.events.Event.RESIZE, resize);
        init();
    }
}

Set the stage scale mode to "no border": 将舞台比例模式设置为“无边框”:

import flash.display.StageScaleMode;

 stage.scaleMode = StageScaleMode.NO_BORDER;

You could try this tutorial 你可以试试这个教程

Very simple and well defined. 非常简单明确。 I'm using the same approach for my projects and works fine. 我对我的项目使用相同的方法并且工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM