缩放容器不会影响子容器的宽度
我有一个容器(精灵),其中添加了子元素(精灵)。 当我缩放容器时,我想获得子级的新宽度,但是当我追踪子级的宽度时,我总是得到原始尺寸,即使所有内容都在视觉上按其应有的比例缩放。 如何覆盖children-width?
更新: 我刚刚发现children.graphics-“dimensions”可能导致了这个问题。当我离开图形时,一切似乎都很好。是否可以与子精灵同时缩放图形?
I've got a container(sprite) with children(sprites) added to it.
When I scale the container, I would like to get the new width of a child, but when I trace the children's width I always get the original dimensions, even though everything gets visually scaled as it should.
How do I overwrite the children-width ?
Update:
I just found out that the children.graphics-"dimensions" could have caused the problem. When I leave the graphics, everything seems ok. Is it possible to scale the graphics at same time as the child-sprite?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
DisplayObject.transform.pixelBounds.width
或DisplayObject.transform.pixelBounds.height
获取子显示对象的宽度和高度,如下所示:DisplayObject.transform.pixelBounds
基本上获取“一个定义舞台上显示对象的边界矩形的Rectangle
对象”。You can use
DisplayObject.transform.pixelBounds.width
orDisplayObject.transform.pixelBounds.height
to get the width and height of the child display objects like in the following:DisplayObject.transform.pixelBounds
basically gets "aRectangle
object that defines the bounding rectangle of the display object on the stage".子级宽度始终是原始的全尺寸值。如果你想获得它们的当前宽度,只需将该值乘以容器的缩放比例即可。
例如,如果您的子宽度为 100 像素,并且您将容器缩放到一半大小:100 像素 * 0.5 = 50 像素。或者使用代码:
actualChildWidth = container.scaleX * child.width;
The children width is always going to be what the original, full scale values are. If you want to get their current width just multiply the value with the scaling ratio of the container.
So for example if your child width is 100 pixels and you scale the container to half size: 100 pixels * 0.5 = 50 pixels. Or with code:
actualChildWidth = container.scaleX * child.width;
我还建议使用显示对象转换的
concatenatedMatrix
。这将返回一个二维变换矩阵乘以对象的父链到根级别。获得生成的 Matrix 对象后,您可以检查其
a
或d
属性以分别查看其根级 x 和 y 缩放因子。I would also recommend using the
concatenatedMatrix
of your display object's transform. That will return a 2D transformation matrix multiplied up the object's parent chain to the root level.Once you have the resulting Matrix object, you can inspect its
a
ord
property to see its root-level x and y scaling factors respectively.