AS3:绘制重叠的矩形,以一个精灵和应用阿尔法 [英] As3: Draw overlapping rectangles to a sprite and apply alpha

查看:261
本文介绍了AS3:绘制重叠的矩形,以一个精灵和应用阿尔法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要画的 independet 矩形来一个精灵。但在重叠的区域将得到明显的,如果我申请的字母以我的精灵(精灵会淡入淡出):

I need to draw independet rectangles to a sprite. But the overlapping areas will get visible if I apply alpha to my sprite (the sprite will be fade in and out):

        var spBox:Sprite = new Sprite();
        this.addChild(spBox);

        spBox.graphics.beginFill(0x123456)
        spBox.graphics.drawRect(100, 100, 50, 50);
        spBox.graphics.endFill();

        spBox.graphics.beginFill(0x123456)
        spBox.graphics.drawRect(125, 125, 50, 50);
        spBox.graphics.endFill();

有没有办法为 compine /平化/合并我的精灵的矩形?我希望有一个无缝APLHA appearence。

Is there a way to compine/flatten/merge the rectangles of my sprite? I want a seamless aplha appearence.

推荐答案

我怀疑对象的图形不支持这种功能,为它的数据部分。

I suspect that the graphics object does not support this kind of functionality for parts of its data.

如果这两个框是单独的的DisplayObject ,你可以设置的 .blendMode 级DisplayObjectContainer BlendMode.LAYER,这给了想要的结果。下面是一些例子code表示refactors一个矩形的绘制成类:

If both boxes are individual DisplayObjects, you can set the .blendMode of the DisplayObjectContainer to BlendMode.LAYER, which gives the desired result. Here's some example code that refactors the drawing of a rectangle into a Box class:

var spBox:Sprite = new Sprite();
this.addChild(spBox);


var a:Box = new Box(50, 50, 0x123456);
a.x = a.y = 100;
spBox.addChild(a);  

var b:Box = new Box(50, 50, 0x123456);
b.x = b.y = 125;
spBox.addChild(b);    

spBox.alpha = .5;
spBox.blendMode = BlendMode.LAYER;

类看起来像这样的相关部分:

The relevant parts of the Box class look like this:

public class Box extends Shape
{
    public function Box(width:Number = 100, height:Number = 100, color:uint = 0)
    {
        graphics.beginFill(color)
        graphics.drawRect(0, 0,  width, height);
        graphics.endFill();
    }
}

这篇关于AS3:绘制重叠的矩形,以一个精灵和应用阿尔法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆