沐风白桦

大圣休得胡闹

BitmapData.draw() 和 DisplayObject.blendMode

| Comments

BitmapData.draw()如果遇到DisplayObject.blendMode有时候效果会异常,这里有个陷阱…oops

simple exmaple
1
2
3
4
5
6
7
8
9
10
11
var container:Sprite = new [some DisplayObjectContainer class]();
var childA:Sprite = new [some DisplayObject class]();
var childB:Sprite = new [some DisplayObject class]();

childA.blendMode = BlendMode.ADD;

container.addChild(childA);
container.addChild(childB);

var data:BitmapData = new BitmapData(container.width, container.height, true, 0);
data.draw(container);

如上面这段代码,看起来没有什么问题,但是如果把data通过Bitmap显示出来,就会发现效果有些诡异,这是因为BitmapDatadraw的时候,会自动忽略childA.blendMode属性,除非把childA的父级容器设置为container.blendMode = BlendMode.LAYER

Comments