规模,位置和放大器;旋转父对象,使子对象占用整个舞台 [英] Scale, Position & Rotate Parent object to make child object take up entire stage
问题描述
使用下面的第一张照片,让我们说:
Using the first photo below, let's say:
- 的红色轮廓是舞台的边界
- 灰色方块是一个
雪碧
在舞台上。 - 绿框是灰色框的孩子,有一个旋转集。
- 在两个显示对象都挂靠在左上角(0,0)。
- The red outline is the stage bounds
- The gray box is a
Sprite
on the stage. - The green box is a child of the gray box and has a rotation set.
- both display object are anchored at the top-left corner (0,0).
我想旋转,缩放和位置的灰色框,这样的绿色框填充阶段边界(绿框和舞台具有相同的纵横比)。
I'd like to rotate, scale, and position the gray box, so the green box fills the stage bounds (the green box and stage have the same aspect ratio).
我可以否定旋转很轻松了。
I can negate the rotation easily enough
parent.rotation = -child.rotation
但比例和位置被证明(因为旋转)棘手。我可以使用一些帮助与数学参与计算的比例和位置。
But the scale and position are proving tricky (because of the rotation). I could use some assistance with the Math involved to calculate the scale and position.
这就是我曾经试过,但没有产生我希望的结果:
This is what I had tried but didn't produce the results I expected:
gray.scaleX = stage.stageWidth / green.width;
gray.scaleY = gray.scaleX;
gray.x = -green.x;
gray.y = -green.y;
gray.rotation = -green.rotation;
我不可怕经历了转换矩阵,但假设我需要走这条路。
I'm not terribly experienced with Transformation matrices but assume I will need to go that route.
下面是一个样本的.fla什么我正与: <一href="https://onedrive.live.com/redir?resid=63769E610023150C!320&authkey=!AALiAyuzay7__tQ&ithint=file,.fla"相对=nofollow> SampleFile
Here is an .fla sample what I'm working with: SampleFile
推荐答案
有关后人,这里是我结束了使用。我创建了一个精灵/影片剪辑里面的孩子(绿色)框,并给了它innerObj的一个实例名称(使之成为真正的内容)。
For posterity, here is what I ended up using. I create a sprite/movieClip inside the child (green) box and gave it an instance name of "innerObj" (making it the actually content).
var tmpRectangle:Rectangle = new Rectangle(greenChild.x, greenChild.y, greenChild.innerObj.width * greenChild.scaleX, greenChild.innerObj.height * greenChild.scaleY);
//temporary reset
grayParent.transform.matrix = new Matrix();
var gs:Number=stage.stageHeight/(tmpRectangle.height); // get scale ratio
var mat:Matrix=grayParent.transform.matrix;
mat.scale(gs,gs);
mat.translate(-gs * tmpRectangle.x, -gs * tmpRectangle.y);
mat.rotate( -greenChild.rotation * Math.PI / 180);
grayParent.transform.matrix = mat;
这篇关于规模,位置和放大器;旋转父对象,使子对象占用整个舞台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!