我有一个电影剪辑(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;
}当我使用调试在不同的手机上运行它时,它锁定在左手角,但它确实延伸到适合整个屏幕。我该怎么办?
发布于 2013-12-10 14:22:41
如果您的内容在调整大小和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;https://stackoverflow.com/questions/20485766
复制相似问题