1

我需要在保持 AS3 中的纵横比的情况下缩放图像。它应该被缩放到完整的舞台大小,但不应该被切断。

怎么做?

谢谢你,乌利

4

1 回答 1

8

像这样的东西应该工作:

// set the scale to fit the width of the image to the width of the stage     
var scale:Number =  stage.stageWidth / myImage.width;

// if the height of the image will be taller than the stage,
// set the scale to fit the height of the image to the height of the stage
if(myImage.height * scale > stage.stageHeight){
    scale = stage.stageHeight / myImage.height;
}   

// apply the scale to the image
myImage.scaleX = myImage.scaleY = scale;
于 2012-11-21T22:47:29.597 回答