简体   繁体   English

Flash AS3:如何在另一个Rect中调整Rect的大小?

[英]Flash AS3: How to Resize a Rect within another Rect?

I've got a tricky one that's stumping me, could you take a quick look over it please... 我遇到了一个棘手的问题,请您快速浏览一下...

I draw a rectangle within another rectangle like this (I use it as a mask): 我在另一个这样的矩形中绘制一个矩形(我将其用作遮罩):

CanvasBorder.graphics.beginFill(0xf0ff00,0.1);  
CanvasBorder.graphics.drawRect(100,100,550, 300);
CanvasBorder.graphics.drawRect((stage.stageWidth/2-Canvas.width/2),(stage.stageHeight/2-Canvas.height/2),250, 150);
CanvasBorder.graphics.endFill();

effectively its a 550x300 box with a 250x150 cutout. 有效地是550x300的框,其尺寸为250x150。

Within one of my functions I need to resize the INNER 'cut-out' box from 250x150 to 150x100 - but keep the OUTER box exactly the same. 在我的一项功能中,我需要将“内部”剪切框的尺寸从250x150调整为150x100-但要使外部框完全相同。

Normally when I'd resize a normal rectangle I'd do this: 通常,当我调整普通矩形的大小时,可以这样做:

rectangle .width = 150;
rectangle .height = 100;

But this solution doesn't work and I don't know how to reference the cutout of the shape. 但是此解决方案不起作用,我也不知道如何引用形状的切口。 Any ideas please I'm really struggling with this one and can't find anything on google. 任何想法,请问我真的很为此挣扎,无法在Google上找到任何东西。

thanks for your time 谢谢你的时间

ChainsawDR 电锯DR

Maybe you can create ANOTHER Sprite or Shape like this: 也许您可以这样创建另一个SpriteShape

// somewhere in your code declare the rectangleMask
var rectangleMas:Shape;


rectangleMask = new Shape();
// draw the rectangle the same way
// and add it to CanvasBorder (I assume that CanvasBorder is a DisplayObjectContainer)
CanvasBorder.addChild(rectangleMask);

Then you can just do the resize as you want: 然后,您可以根据需要调整大小:

rectangleMask.witdth = 150;
rectangleMask.height = 100;

If you want that rectangle to be a mask of CanvasBorder you can do this: 如果您希望该矩形成为CanvasBorder的蒙版,则可以执行以下操作:

CanvasBorder.mask = rectangleMask;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM