flash – 如何使用StageScaleMode.SHOW_ALL获取舞台尺寸?
发布时间:2020-12-15 07:23:55 所属栏目:百科 来源:网络整理
导读:如果将stage.scaleMode设置为StageScaleMode.SHOW_ALL,则可以按比例放大或缩小swf,并可以在顶部/底部或左/右填充.但是,stage.width高度始终返回swf定义的宽度和高度,stage.scaleX Y始终返回1.据我所知,不会抛出调整大小事件.那么我如何得到实际的尺度和尺寸
|
如果将stage.scaleMode设置为StageScaleMode.SHOW_ALL,则可以按比例放大或缩小swf,并可以在顶部/底部或左/右填充.但是,stage.width高度始终返回swf定义的宽度和高度,stage.scaleX Y始终返回1.据我所知,不会抛出调整大小事件.那么我如何得到实际的尺度和尺寸?
我想要他们两个问题: >我只想在用户可以看到的情况下,在顶部/底部或左/右填充填充物. 解决方法
在您的情况下,使用StageScaleMode.NO_SCALE并自行编码调整大小可能更容易:
stage.addEventListener(Event.RESIZE,onStageResize);
private function onStageResize(event : Event) : void
{
var stageW : int = stage.stageWidth;
var stageH : int = stage.stageHeight;
var contentW : int = yourVisibleContent.width;
var contentH : int = yourVisibleContent.height;
// resize it to fit
var canvasAspectRatio : Number = stageW / stageH;
var contentAspectRatio : Number = contentW / contentH;
if(canvasAspectRatio > contentAspectRatio)
{
yourVisibleContent.height = stageH;
yourVisibleContent.width = yourVisibleContent.height * contentAspectRatio;
} else {
yourVisibleContent.width = stageW;
yourVisibleContent.height = yourVisibleContent.width / contentAspectRatio;
}
// center it:
yourVisibleContent.x = (stageW - yourVisibleContent.width) / 2;
yourVisibleContent.y = (stageH - yourVisibleContent.height) / 2;
// fill remaining space with black:
graphics.beginFill(0x000000);
if(canvasAspectRatio > contentAspectRatio)
{
var horizontalEmptySpace : Number = stageW - yourVisibleContent.width;
graphics.drawRect(0,horizontalEmptySpace / 2,stageH);
graphics.drawRect(stageW - horizontalEmptySpace / 2,stageH);
}else{
var verticalEmptySpace : Number = stageH - yourVisibleContent.height;
graphics.drawRect(0,stageW,verticalEmptySpace / 2);
graphics.drawRect(0,stageH - verticalEmptySpace / 2,verticalEmptySpace / 2);
}
// now you can also redraw your bitmaps with higher resolutions
// it is easy to read the scale of your content with: yourVisibleContent.scaleX and yourVisibleContent.scaleY
}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
