【问题标题】:ActionScript 3 Bitmap width proportional to heightActionScript 3 位图宽度与高度成比例
【发布时间】:2017-07-21 15:39:19
【问题描述】:
我有这样定义的位图:
[Embed(source="images/floorplan.png")]
var Floorplan:Class;
var floorplanImg:Bitmap = new Floorplan();
floorplanImg.y = 510;
floorplanImg.x = 40;
floorplanImg.height = 890;
我要做的是设置高度并使宽度与高度成正比。我尝试用谷歌搜索我的问题,但我看到的只是如何缩放位图图像。自从我完成 ActionScript 3 以来已经有很长时间了,我似乎无法弄清楚这一点。请帮忙。
【问题讨论】:
标签:
actionscript-3
bitmap
【解决方案1】:
在 AS3 中,您可以使用显示对象的 scaleX 和 scaleY 属性来保持原生纵横比。
这是按比例缩放项目的常用方法:
floorplanImg.height = 890; //when you change the height, it automatically changes the scaleY to the relative amount from the original (1)
floorplanImg.scaleX = floorplanImg.scaleY; //make the scaleX the same as the new scaleY to keep the aspect ratio the same
缩放属性基本上只是相对于宽度/高度的替代 - 1 是原始大小,2 是两倍大小,0.5 是一半等等......