如何防止 AS3 舞台上的影片剪辑对象的外部翻译?

发布于 2024-08-26 10:27:00 字数 838 浏览 5 评论 0原文

我有一个 MovieClip 对象,该对象在 .swc 文件中导出为动作脚本 (AS3)。

当我将剪辑的实例放置在舞台上而不进行任何修改时,它出现在左上角,大约在舞台外的一半(即只有对象的右下象限可见)。据我了解,这是因为剪辑有一个注册点,该注册点不是左上角。

如果你在影片剪辑上调用 getBounds() ,你可以获得剪辑的边界(大概是从它对齐的“点”开始),看起来像(左:-303,上:-100,右:303,下: 100),您可以从剪辑 x 和 y 中减去左侧和顶部的值:

clip.x -= bounds.left;
clip.y -= bounds.top;

这似乎可以将剪辑在舞台上完全对齐,剪辑的左上角正好位于舞台的一角。

但!当将其对齐到舞台中心时,遵循该逻辑似乎不起作用!

clip.x = (stage.stageWidth / 2);
etc...

这创造了疯狂的平行宇宙,剪辑现在位于舞台的右下角。

我唯一的线索是查看:

clip.transform.matrix

clip.transform.concatenatedMatrix
  • 矩阵的 tx 值为 748(舞台高度的一半) ty 值为 426(舞台高度的一半)

  • concatenatedMatrix 的 tx 值为 1699.5,ty 值为 967.75

这也显然是影片剪辑正在定位,但为什么呢?这个额外的翻译来自哪里?

I have a MovieClip object, which is exported for actionscript (AS3) in an .swc file.

When I place an instance of the clip on the stage without any modifications, it appears in the upper left corner, about half off stage (i.e. only the lower right quadrant of the object is visible). I understand that this is because the clip has a registration point which is not the upper left corner.

If you call getBounds() on the movieclip you can get the bounds of the clip (presumably from the "point" that it's aligned on) which looks something like (left: -303, top: -100, right: 303, bottom: 100), you can subtract the left and top values from the clip x and y:

clip.x -= bounds.left;
clip.y -= bounds.top;

This seems to properly align the clip fully on stage with the top left of the clip squarely in the corner of the stage.

But! Following that logic doesn't seem to work when aligning it on the center of the stage!

clip.x = (stage.stageWidth / 2);
etc...

This creates the crazy parallel universe where the clip is now down in the lower right corner of the stage.

The only clue I have is that looking at:

clip.transform.matrix

and

clip.transform.concatenatedMatrix
  • matrix has a tx value of 748 (half of stage height) ty value of 426 (Half of stage height)

  • concatenatedMatrix has a tx value of 1699.5 and ty value of 967.75

That's also obviously where the movieclip is getting positioned, but why? Where is this additional translation coming from?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请持续率性 2024-09-02 10:27:01

我相信我已经解决了问题。

似乎当舞台未设置为特定尺寸时,舞台上的项目(或在我的情况下是这个特定的矢量对象)的比例是相对于某些预设比例/尺寸的(我不确定其起源 - - 通过一些测试,它看起来像是受到舞台比例和尺寸的影响)。

增加舞台的大小会增加缩放值,通过一些矩阵串联,会导致影片剪辑以相同的百分比(与舞台)缩放和平移,即使您明确设置x/y/宽度/高度值。

(注意:不仅仅是动态调整大小。调整窗口大小、关闭并以新大小重新打开窗口会产生相同的行为)

我怀疑这只发生在矢量对象上?

无论如何,解决方法是将舞台设置为明确的宽度和高度。然后对象的平移和缩放似乎使用单位父矩阵,并且一切都按照您的预期进行。

I believe that I have solved the problem.

It seems that when the stage is not set to specific dimensions, the scale of the items (or this particular vector object in my case) on the stage is relative to some preset scale/dimensions (The origin of which I'm not sure -- with some testing it looks like it is affected by the ratio and dimensions of the stage).

Increasing the size of the stage increases that scaling value, which through some set of concatenations of matrices results in the movieclip getting scaled and translated at that same percentage (as the stage), even if you explicitly set the x/y/width/height values.

(Note: not just resizing dynamically. Resizing the window, closing and re-opening the window at that new size produces the same behavior)

I suspect this only happens with vector objects?

Anyway, the fix is to set the stage to an explicit width and height. Then the translation and scaling of the object appear to use an identity parent matrix, and everything works like you'd expect.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文