将对象相互混合但不与背景 Actionscript 3
我有许多对象(表示为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果将对象放入容器中,并将其从舞台中删除,则可以使用 BitmapData 类绘制它并创建一个表示组合的新 Bitmap 对象。这将有一个透明的背景,并且它的混合模式将是正常的,允许您在背景上使用它。
(未经测试的代码,祝你好运)
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.
(untested code, good luck)
有一些选项可以让 Flash 自动光栅化图层及其子图层,而不是亲自绘制位图。尝试:
或尝试:
或尝试:
这些选项中的任何一个都应该导致子项在引擎盖下渲染为位图,从而使它们在背景上的单独混合模式/效果无效。
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:
or try:
or try:
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.