使用MovieClip.transform.matrix进行变换问题

发布于 2024-07-26 19:57:11 字数 84 浏览 4 评论 0原文

我在处理 Flash cs4 中的变换时遇到问题......

当我旋转我的影片剪辑并跟踪输出时,我的影片剪辑的宽度也发生了变化......

I have problem when dealing with transform in Flash cs4 ....

When I rotate my movieclip and trace the output, my movieclip's width also changed....

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

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

发布评论

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

评论(5

小兔几 2024-08-02 19:57:12

这是 Flash 播放器中的一个错误。 您可以执行以下操作:


选项 1(可能是最好的方法):

创建 MovieClip 的子类并重写宽度和高度的 get 和 set 方法。
让设置器调用 super,并将值存储为私有变量(例如 _width/_height)
当调用 get 时,返回您的私有变量。
由于您使用的是矩阵,因此请覆盖 get 和 set 矩阵函数,使用新函数设置缩放因子,并在调用 super 之前将它们设置为不缩放。
为什么有效: setter 不受此错误的影响。


选项 2:

使用scaleX/scaleY 代替获取宽度/高度,并乘以宽度和高度值以获得0 旋转、1.0 缩放。
为什么有效:scaleX/scaleY 不受此错误的影响。


快乐编码!

This is a bug in flash player. There are a few things you can do:


Option 1 (probably the best way):

Create a subclass of MovieClip and override the get and set methods for width and height.
Have the setters call super, and store the values as private variables (eg _width/_height)
When get is called, return your private variables.
Since you are using a matrix, override the get and set matrix functions, set the scaling factors with your new functions, and set them to not scale before calling super.
Why this works: The setters are not affected by this bug.


Option 2:

Use scaleX/scaleY instead for getting the width/height, and multiply by the width and height values for 0 rotation, 1.0 scale.
Why this works: The scaleX/scaleY are not affected by this bug.


Happy Coding!

岁吢 2024-08-02 19:57:12

好吧..我的错..我最终看到了我的错误:)。
我之前确信这是一个错误。 尽管布兰登是对的,但我仍然觉得它很令人困惑。 这最终是一个例子,表明布兰登是正确的,并且最后两个值之间没有差异。

var box = new Sprite();
box.graphics.beginFill(0xFF0000);
box.graphics.drawRect(0, 0, 100, 100);
this.addChild(box);

trace(box.width);
box.rotation = 45;
trace(box.width);
box.width = 141.4;
trace(box.width);

编辑:
您可能仍然想检查 PiPeep 的链接表单 grantskinner 描述了我想在上面证明的内容,但成功了(在 Flash CS3 - AS3 中) - http://www.gskinner.com/blog/archives/2007/08/annoying_as3_bu.html

OK .. MY BAD.. I've seen my error eventually :).
I was convinced this was a bug before. Though Branden was right, I still find it pretty confusing. This is eventually an example to show that Branden was right and there is no discrepancy between the last 2 values.

var box = new Sprite();
box.graphics.beginFill(0xFF0000);
box.graphics.drawRect(0, 0, 100, 100);
this.addChild(box);

trace(box.width);
box.rotation = 45;
trace(box.width);
box.width = 141.4;
trace(box.width);

Edit:
You'd still might want to check PiPeep's link form grantskinner describing something like I wanted to prove above, but successuly (in Flash CS3 - AS3) - http://www.gskinner.com/blog/archives/2007/08/annoying_as3_bu.html

扛刀软妹 2024-08-02 19:57:12

我意识到这是一篇相当老的帖子,所以如果这违反了论坛关于死亡帖子或其他什么的礼仪,我深表歉意。 然而,这是谷歌搜索一个相当微不足道的问题的第一个结果,并且似乎并没有真正提供检索显示对象的未旋转宽度或高度的体面方法。

问题是,通过询问宽度和高度,您似乎获得了对象的全局边界,当您想要的是局部边界时,这就是您执行此操作的方法:(只需将整个对象复制并粘贴到闪存中文件并编译看看我的意思)。

import flash.display.Sprite;

var spr=new Sprite()
spr.graphics.beginFill(0xff0000);
spr.graphics.drawRect(-25,-100,50,200);
addChild(spr);

spr.y=150
spr.x=300
function myOEF(e)
{
    spr.rotation++
    trace(spr.width,spr.height);
    var bounds=spr.getBounds(this)
    trace("A: Global bounds: "+bounds);
    var bounds=spr.getBounds(spr)
    trace("B: Local bounds: "+bounds);
}

addEventListener("enterFrame",myOEF);

I realise this is a pretty old post, so my apologies if this is breaking forum etiquette on necroposting or what ever. However, this was the first result on a google search for a fairly trivial problem and does not really seem to offer a decent way of retrieving the unrotated width or height of a display object.

The problem is that by asking for width and height, you seem to be getting the global bounds of the object, when what you want are the local bounds, this is how you do that: (just copy and paste the whole thing into a flash file and compile to see what I mean).

import flash.display.Sprite;

var spr=new Sprite()
spr.graphics.beginFill(0xff0000);
spr.graphics.drawRect(-25,-100,50,200);
addChild(spr);

spr.y=150
spr.x=300
function myOEF(e)
{
    spr.rotation++
    trace(spr.width,spr.height);
    var bounds=spr.getBounds(this)
    trace("A: Global bounds: "+bounds);
    var bounds=spr.getBounds(spr)
    trace("B: Local bounds: "+bounds);
}

addEventListener("enterFrame",myOEF);
笨死的猪 2024-08-02 19:57:12

我不确定为什么这是一个问题 - 这是预期的行为。 剪辑的宽度是从最左边缘到最右边缘的实际像素数 - 如果旋转剪辑,宽度将会发生变化。 如果您的剪辑中包含子剪辑,则该剪辑的宽度不会改变,因为它的旋转可能不会改变。

I'm not sure why this is a problem - it's expected behavior. The width of a clip is the actual number of pixels from the left most edge to the right most edge - which will change if a clip is rotated. If your clip has a sub-clip within it, that clip's width will not change, since presumably it's rotation isn't changing.

热血少△年 2024-08-02 19:57:12

当您旋转剪辑时,宽度/高度将发生变化。 如果您不想要这种行为,请改用scaleX/scaleY 属性。

width/height will change as you rotate the clip. if you don't want this behaviour, use the scaleX/scaleY properties instead.

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