开发者

How to prevent external translation of a movieclip object on stage in AS3?

开发者 https://www.devze.com 2022-12-23 23:33 出处:网络
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,

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消