我试图在MovieClip的每个角落绘制4个方框,但无法弄清楚如何检测右上角,左下角和右下角。有没有更简单的解决方案可以用来替换这种技术或让它起作用?感谢
以下代码是一个旋转135度的矩形。
var square:MovieClip = new MovieClip();
square.graphics.lineStyle(2,0x00ff00);
square.graphics.beginFill(0x0000FF);
square.graphics.drawRect(0,0,100,50);
square.graphics.endFill();
square.x = 200;
square.y = 150;
square.rotation = 135;
addChild(square);
trace(square.getBounds(square));
trace(this.getBounds(square));
trace(this.getBounds(this));
答案 0 :(得分:2)
getBounds()
方法返回一个矩形对象,其中x和y坐标/显示对象的宽度和高度相对于作为参数传递的对象。所以:
square.getBounds(stage);
将为您提供相对于舞台的方块位置的矩形(假设方格是舞台的子节点,但它可以是任何父显示对象)。要访问坐标和尺寸,您可以像这样使用它。
var bounds = square.getBounds(stage);
trace(bounds.x);
trace(bounds.y);
trace(bounds.width);
trace(bounds.height)
<强>更新强>
啊,我认为你需要找到旋转框的角落,而不是边界区域的角落。在这种情况下,您可以使用一些三角法来处理旋转角度,并找到角落偏移的长度。
但如果我明白你要做什么,我认为这是不必要的。如果你需要在方形影片剪辑的角上画一些东西(比如说另一个盒子),你可以将它们作为方形的子项添加。这样,如果旋转父方块,所有子影片剪辑都将随之旋转。所以:
var square:MovieClip = new MovieClip();
//... all your code from above to draw the square
var clip:MovieClip = new MovieClip();
//...some code here to draw some graphics in your clip
//Put the clip at the bottom right corner of the square
clip.x = square.width;
clip.y = square.height;
square.addChild(clip);
答案 1 :(得分:0)
在这里,我已经绘制了两个矩形作为主矩形的子项,它们将旋转,当您的父矩形将旋转或移动时它们将移动...
var widthSquare:int = 100; var heightSquare:int = 50;
var square:MovieClip = new MovieClip(); square.graphics.lineStyle(2,0x00ff00); square.graphics.beginFill(0x0000FF); square.graphics.drawRect(0,0,widthSquare,heightSquare); square.graphics.endFill(); square.x = 200; square.y = 150; square.rotation = 135; 的addChild(正方形);
var square1width:int = widthSquare-(widthSquare-20); //如果square1的宽度是20减去20 var square1height:int = heightSquare-(heightSquare-10); //如果square1的高度是10减去10
var square1:MovieClip = new MovieClip(); square1.graphics.lineStyle(2,0x000000); square1.graphics.beginFill(0x000000处); square1.graphics.drawRect(0,0,square1width,square1height); square1.graphics.endFill(); square.addChild(square1);
var square2width:int = widthSquare-(widthSquare-30); //如果square2的宽度是30减去30 var square2height:int = heightSquare-(heightSquare-15); //如果square2的高度是15减去15
var square2:MovieClip = new MovieClip(); square2.graphics.lineStyle(2,0x000000); square2.graphics.beginFill(0x000000处); square2.graphics.drawRect(0,0,square2width,square2height); square2.graphics.endFill(); square2.x = widthSquare-square2width; square2.y = heightSquare-square2height; square.addChild(square2);
// square.rotation = 35;
希望这会对你有所帮助..试试吧。