gpt4 book ai didi

actionscript-3 - AS3 MovieClip getRealBounds

转载 作者:行者123 更新时间:2023-12-02 05:21:40 26 4
gpt4 key购买 nike

如您所知,在 as3 中我们有一个 getBounds() 方法,该方法返回我们想要的 DisplayObject 容器中影片剪辑的确切尺寸和坐标。事实上,这些数据是根据调用 getBounds() 时帧中 MC 中的图形状态计算的。

我想要的是真正的边界矩形,即整个动画影片剪辑将在其容器中采用的较大矩形。
我想到了两个办法:
1 - 一个我不知道的flash内置方法
2 - 遍历每一帧总是得到边界并最终返回最大的(但是如果它是一个长动画怎么办?我应该等待它完全播放才能得到我想要的东西吗?)

我希望我已经说清楚了。如果您需要示例,请告诉我!

最佳答案

您可以遍历每一帧,而无需等待动画播放:

假设您的剪辑名为 bob:

var lifetimeBounds:Rectangle = new Rectangle();
bob.gotoAndStop(1);
for(var i:int=1;i<=bob.totalFrames;i++){
lifetimeBounds.width = Math.max(lifetimeBounds.width, bob.width);
lifetimeBounds.height = Math.max(lifetimeBounds.height, bob.height);
lifetimeBounds.x = Math.min(lifetimeBounds.x, bob.x);
lifetimeBounds.y = Math.min(lifetimeBounds.y, bob.y);
bob.nextFrame();
}

bob.gotoAndStop(1); //reset bob back to the beginning

它会占用更多的 CPU 资源(因此,如果上述方法适合您的情况,我建议您不要使用它),但您也可以在上面的示例中使用 getBounds() 并将返回的矩形与lifetimeBounds 矩形:

var tempRect:Rectangle;
var lifetimeBounds:Rectangle = new Rectangle();
bob.gotoAndStop(1);
for(var i:int=1;i<=bob.totalFrames;i++){
tmpRect = bob.getBounds(this);
lifetimeBounds.width = Math.max(lifetimeBounds.width, tempRect.width);
lifetimeBounds.height = Math.max(lifetimeBounds.height, tempRect.height);
lifetimeBounds.x = Math.min(lifetimeBounds.x, tempRect.x);
lifetimeBounds.y = Math.min(lifetimeBounds.y, tempRect.y);
bob.nextFrame();
}

关于actionscript-3 - AS3 MovieClip getRealBounds,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13747077/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com