【问题标题】:Does Flash pro automatically adjust my game's resolution for all devices?Flash pro 是否会针对所有设备自动调整我的游戏分辨率?
【发布时间】:2014-03-10 04:45:18
【问题描述】:

我使用 flash pro 创建了我的游戏,我一直在用我的智能手机对其进行测试,它的大小是 480x800。所以我将 FLA 文件中的文档大小设置为 480x800。

但我想知道我的应用是否会自动调整其分辨率以适应其他尺寸,例如 1280x720 和 960x640。

如果没有,我怎样才能让它自动调整其分辨率以尽可能适合任何智能手机的尺寸,但不会丢失 480x800 的比例。所以我希望其他智能手机的任何一侧都有一点空白。或者我想我可以让背景图片比 480x800 大一点?

哦,我的智能手机是 LG Android

【问题讨论】:

    标签: android actionscript-3 flash resolution


    【解决方案1】:

    不,您应该自己做所有事情。您还应该设计游戏,使其在各种屏幕上看起来都不错。

    //Startup of the game, initial settings for the stage, 
    //and getting screen size
    public function Main() {
        addEventListener(Event.ADDED_TO_STAGE, onAdded);
    }
    
    private function onAdded(e:Event):void {
        removeEventListener(Event.ADDED_TO_STAGE, onAdded);
    
        stage.align = StageAlign.TOP_LEFT;
        stage.scaleMode = StageScaleMode.NO_SCALE;
    
        //Width and Height
        trace(stage.stageWidth, stage.stageHeight);
    }
    

    使背景适合任何屏幕尺寸:

    private function fitBackground(background:Bitmap, screenWidth:uint, screenHeight:uint):void {
        var availableRatio:Number = screenWidth / screenHeight;
        var componentRatio:Number = background.width / background.height;
        if (componentRatio < availableRatio) {
            background.width = screenWidth;
            background.height = screenWidth / componentRatio
        } else {
            background.width = screenHeight * componentRatio;
            background.height = screenHeight;
        }
    
        background.x = (screenWidth - background.width) >> 1;
        background.y = (screenHeight - background.height) >> 1;
    }
    
    //Usage
    fitBackground(myBackground, stage.stageWidth, stage.stageHeight)
    

    【讨论】:

    • 您好,谢谢您的回复。我做了第一个代码,我认为它工作得很好。实际上,我没有其他智能手机或平板电脑可以测试它,所以我不确定。有没有办法测试它?就像在虚拟平板电脑中一样?还是我需要购买平板电脑?
    • 我使用 Sprite 作为背景图片,而我的游戏使用 3 种不同的背景。因此该功能无法显示错误。所以我把参数类型改成了:private function fitBackground(background:GameBgMyOwn, screenWidth:uint, screenHeight:uint):void {
    • 因为我的背景被声明为 GameBgMyOwn 这是一个精灵。 gameBg = new GameBgMyown(); addChild(gameBg); fitBackground(gameBg, stage.stageWidth, stage.stageHeight); // 然后我在这里调用函数
    • 但它给了我一个错误:1046:找不到类型或不是编译时常量:GameBgMyOwn。
    • 检查 ActionScript 的所有导出是否正确。如果你的背景不是Bitmap 更好fitBackground(background:DisplayObject, screenWidth:uint, screenHeight:uint)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-08
    • 1970-01-01
    相关资源
    最近更新 更多