我想集中在我的舞台大影片剪辑(1400像素宽)在舞台上调整大小。这个大影片剪辑移动到正确的某些事件,所以我不能使用这样的代码:

currentPage.x = ((stage.stageWidth/2) - (currentPage.width/2))

时有办法也许使用其选自0和使用,在定心偏移量(阶段“视口”的左侧)偏置?

在动画片段只改变x中。

有帮助吗?

解决方案

当一个对象的大小时,可以说其规模已经改变。秤是不错的,因为它们使我们能够在百分比的工作。鉴于任何百分比的变化,我们可以将同样的更改任何其他对象获取的相对位置。看这里:

var previousStageWidth:Number;

public function handleResize():void {
    //calculate the difference in stage with as a percentage
    var widthScale:Number = previousStageWidth / stage.stageWidth;

    //scale the x value by the same amount
    myDisplayObject.x *= widthScale;

    //update the previous value for the next resize
    previousStageWidth = stage.stageWidth;
}

希望,你的作品了。

其他提示

我宁愿让容器精灵的所有内容。内侧容器,一切都被测量为如果场景总是400x300的(或者需要的任何其它固定大小,不管纵横比)。当场景被调整大小,我调整大小和定心只容器以配合内部:

//not really tested because my real code is more complex, so watch out...
var bounds:Rectangle = container.getRect(null);
//scale factor to fit inside
var scaleFactor:Number = Math.min(stage.stageWidth / bounds.width, stage.stageHeight / bound.height);
container.scaleX = container.scaleY = scaleFactor; //scaling
//centering
container.x = (stage.stageWidth - container.width) * 0.5;
container.y = (stage.stageHeight - container.height) * 0.5;

这样,您就可以处理容器中的任何的剪辑,而不是一个。容器不使用所有的屏幕空间,但保留宽高比。如果你想使用所有的屏幕空间,你要想到你的舞台的动态布局 - 这是唯一可以适当做

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top