作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如您所知,在 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/
如您所知,在 as3 中我们有一个 getBounds() 方法,该方法返回我们想要的 DisplayObject 容器中影片剪辑的确切尺寸和坐标。事实上,这些数据是根据调用 getBounds()
如您所知,在 as3 中我们有一个 getBounds() 方法,该方法返回我们想要的 DisplayObject 容器中影片剪辑的确切尺寸和坐标。事实上,这些数据是根据调用 getBounds()
我是一名优秀的程序员,十分优秀!