将对象相互混合但不与背景 Actionscript 3

发布于 2024-11-25 11:34:52 字数 760 浏览 0 评论 0原文

我有许多对象(表示为 DisplayObjects),我希望将它们相互混合。

然而,在这些对象背后有一个我不想参与混合的背景。

所以基本上我想将这些对象相互混合,然后使用此混合的结果作为新的 DisplayObject(例如将其放在随机颜色的背景之上)。

所以我所拥有的是:

var obj1:DisplayObject = getFirstObj();
var obj2:DisplayObject = getSecObj();
var background:DisplayObject = getBackground();

obj1.blendMode = BlendMode.ADD;
obj2.blendMode = BlendMode.ADD;

我尝试的第一次尝试是将这些对象放入一个公共 DisplayObjectContainer 中,希望混合模式仅相对于同一 DisplayObjectContainer 包含的所有对象,但情况似乎并非如此。

var objectsPool:Sprite = new Sprite();
objectsPool.addChild( obj1 );
objectsPool.addChild( obj2 );

addChild( background );
addchild( objectsPool );

所以这并没有让我到任何地方。 任何帮助表示赞赏。

编辑:在最后一个代码片段中将 DisplayObjectContainer 更改为 Sprite

I have a number of objects (represented as DisplayObjects) that i wish to blend with eachother.

However behind these objects there is a background that i do not want to involve in the blending.

So basically i want to blend these objects with eachother and afterwards use the result of this blending as a new DisplayObject (for example to put it on top of a randomly colored background).

So what i have is:

var obj1:DisplayObject = getFirstObj();
var obj2:DisplayObject = getSecObj();
var background:DisplayObject = getBackground();

obj1.blendMode = BlendMode.ADD;
obj2.blendMode = BlendMode.ADD;

A first attempt i tried was putting these objects into a common DisplayObjectContainer hoping that blending mode would only be relative to all objects contained by the same DisplayObjectContainer, but this does not seem to be the case.

var objectsPool:Sprite = new Sprite();
objectsPool.addChild( obj1 );
objectsPool.addChild( obj2 );

addChild( background );
addchild( objectsPool );

So that diddent get me anywhere.
Any help is appreciated.

EDIT: changed DisplayObjectContainer to Sprite in the last code snippet

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如果没有你 2024-12-02 11:34:52

如果将对象放入容器中,并将其从舞台中删除,则可以使用 BitmapData 类绘制它并创建一个表示组合的新 Bitmap 对象。这将有一个透明的背景,并且它的混合模式将是正常的,允许您在背景上使用它。

var obj1:DisplayObject = getFirstObj();
var obj2:DisplayObject = getSecObj();
var background:DisplayObject = getBackground();

obj1.blendMode = BlendMode.ADD;
obj2.blendMode = BlendMode.ADD;

var objectsPool:DisplayObjectContainer = new DisplayObjectContainer();
objectsPool.addChild( obj1 );
objectsPool.addChild( obj2 );

var bmd:BitmapData = new BitmapData(objectsPool.width,objectsPool.height,true,0);
bmd.draw(objectsPool);

var drawnObject:Bitmap = new Bitmap(bmd);

addChild( background );
addchild( drawnObject );

(未经测试的代码,祝你好运)

If you put the objects into a container, and remove it from the stage, you can then draw it with the BitmapData class and create a new Bitmap object representing the combination. This will have a transparent background, and it's blendMode will be normal, allowing you to use it on the background.

var obj1:DisplayObject = getFirstObj();
var obj2:DisplayObject = getSecObj();
var background:DisplayObject = getBackground();

obj1.blendMode = BlendMode.ADD;
obj2.blendMode = BlendMode.ADD;

var objectsPool:DisplayObjectContainer = new DisplayObjectContainer();
objectsPool.addChild( obj1 );
objectsPool.addChild( obj2 );

var bmd:BitmapData = new BitmapData(objectsPool.width,objectsPool.height,true,0);
bmd.draw(objectsPool);

var drawnObject:Bitmap = new Bitmap(bmd);

addChild( background );
addchild( drawnObject );

(untested code, good luck)

时光清浅 2024-12-02 11:34:52

有一些选项可以让 Flash 自动光栅化图层及其子图层,而不是亲自绘制位图。尝试:

container.cacheAsBitmap = true;

或尝试:

container.blendMode = "layer";

或尝试:

container.filters = [new GlowFilter(0,0,0,0)];

这些选项中的任何一个都应该导致子项在引擎盖下渲染为位图,从而使它们在背景上的单独混合模式/效果无效。

Rather going to the effort of drawing a Bitmap yourself, there are options that cause Flash to rasterize a layer and it's children automatically. Try:

container.cacheAsBitmap = true;

or try:

container.blendMode = "layer";

or try:

container.filters = [new GlowFilter(0,0,0,0)];

Any of those options should cause the children to render into a Bitmap under the hood, invalidating their individual blend modes/effects on the background.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文