如何根据屏幕尺寸调整我的影片剪辑大小?

时间:2013-12-10 03:57:31

标签: android actionscript-3 flash

我有一个影片剪辑(startMenu);里面有按钮,文字和图形。这是我正在制作的游戏,它将在Android的不同屏幕尺寸上播放。这是我到目前为止的代码:

stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT
startMenu.addEventListener(Event.RESIZE, resizeLayout);
function resizeLayout(e:Event):void
{
    setPosition();
}
function setPosition():void
{
     startMenu.x = (stage.stageWidth - startMenu.width) / 2;
        startMenu.y = (stage.stageHeight - startMenu.height) /2;
}

当我使用调试在不同的手机上运行它时,它会锁定在左上角,但确实伸展到适合整个屏幕。我该怎么办?

1 个答案:

答案 0 :(得分:0)

如果您的内容在调整大小时延伸,而stage.scaleMode = StageScaleMode.NO_SCALE;您可能会在某处修改剪辑的宽度/高度。

由于我看不到你的代码库,我只能想象它会是这样的:

// deforms the image
myClip.width = stage.fullScreenWidth;
myClip.height = stage.fullScreenHeight;

相反,您应该仅调整一个尺寸并调整其他百分比,如下所示:

// keeps ratio
myClip.width = stage.fullScreenWidth;
myClip.scaleY = myClip.scaleX;

当然,你不能总是知道在哪一方扩展内容,所以你可能想先检查哪一方更大。例如:

if (myClip.width > myClip.height)
{
    myClip.width = stage.fullScreenWidth;
    myClip.scaleY = myClip.scaleX;
}
else
{
    myClip.height = stage.fullScreenHeight;
    myClip.scaleX = myClip.scaleY;
}

然后,就像你一样,将剪辑与容器对齐:

// multiplication works faster, keep that in mind if resizing on each frame or something like this
// But more importantly - getting width/height is pretty expensive, for frequent resizing pre-calculate and store the width height to avoid recalculation
startMenu.x = (stage.stageWidth - startMenu.width) * .5;
startMenu.y = (stage.stageHeight - startMenu.height) * .5;