【问题标题】:See through the second layer according the position of the third one - Flash根据第三层的位置看透第二层——Flash
【发布时间】:2015-04-23 00:08:56
【问题描述】:

我是新来的,如果我的问题很愚蠢,对不起我的英语。 我的问题是我有三层,如下图所示。

“Layer 1”的背景为蓝色,“Layer 2”的颜色为绿色。第 3 层具有透明背景的图像。我想根据图像边距删除第二层。无论我在哪里移动图像,我都需要删除第二层。想要的结果显示在第二张图片上。

【问题讨论】:

  • 嗨,tonitox,欢迎来到 StackOverflow!如果您的英语不好,请不要担心,因为通常会有人来编辑您的帖子以澄清它。不过,您将不得不多描述一下您的意思。 “根据图像边距删除”是什么意思?
  • 如第二张图片所示。我的意思是应该删除第二层图像在哪里。我的意思是图像的大小。换句话说,这个想法是在图像的正下方显示第一层。我希望你能理解我的意思。

标签: actionscript-3 flash layer


【解决方案1】:

您需要命名您的对象,以便您可以针对它们进行编程。因为空格会导致错误的变量名称,所以我们将对象命名如下:

  • 第 1 层 = blue
  • 第 2 层 = green
  • 第 3 层 = person

解决方案

您需要一个遮罩,但与普通遮罩不同,您需要遮罩形状的反转(即,内部是隐藏,而不是内部是显示) .您可以使用BlendMode.ERASE 实现此目的。然后,只需匹配person 的位置和尺寸;每当您移动 person 时,也要更新遮罩的位置。

function make(color:uint, width:Number, height:Number, x:Number = 0, y:Number = 0, existingShape:Sprite = null):Sprite {
    // Helper function to make squares.  Will create a new one, or draw on one provided.
    var s:Sprite;
    if (existingShape != null) {
        s = existingShape;
    } else {
        s = new Sprite();
    }
    s.graphics.beginFill(color, 1);
    s.graphics.drawRect(x, y, width, height);
    s.graphics.endFill();
    return s;
}

// Layer 1
var blue:Sprite = make(0x3f48cc, 250, 400);
addChild(blue);

// Layer 2
var green:Sprite = make(0x00cc99, 250, 400);
addChild(green);
green.blendMode = BlendMode.LAYER;

// Layer 3
var person:Sprite = make(0xea0502, 20, 100, 20); // arms
make(0xea0502, 60, 20, 0, 20, person); // head and legs
addChild(person);
person.x = 95;
person.y = 150;

// This is the mask.  It must be a child of the object it is masking.
var boundary:Sprite = make(0xff00e4, person.width, person.height);
green.addChild(boundary);
boundary.x = person.x;
boundary.y = person.y;
boundary.blendMode = BlendMode.ERASE;

结果

【讨论】:

  • 是的,这就是我想要的。谢谢
猜你喜欢
  • 1970-01-01
  • 2023-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多