如何在车上切一个“洞”在矩形精灵内部以查看下面的精灵? (动作脚本 3)
每次我用谷歌搜索这个问题时,我都会看到有关蒙版和混合的令人困惑的信息,这些信息似乎都不能直接应用于我认为应该是一件简单的事情......
这里涉及三个精灵......最底层的精灵几乎是一个背景。我想在背景上覆盖一个半透明的精灵,然后我想让第三个、最上面的精灵充当一个洞,这样第三个精灵内部的区域就完全透明了,这样背景精灵就完全可见了。
我将如何动态地执行此操作(即使用 Actionscript 图形调用动态绘制遮罩精灵和孔)?
Everytime I google this question I see confusing information about masks and blends, none of which seems to directly apply to what I think should be an easy thing...
There are three Sprites involved here...the lowest layer sprite is pretty much a background. I want to overlay a translucent Sprite on top of the background and then I want the third, top-most Sprite to act as a hole, so that the area inside the third Sprite is completely transparent, so that the background sprite is completely visible.
How would I go about doing this dynamically (i.e. dynamically drawing the masking sprite and hole using the Actionscript graphics calls)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我知道这已经是很久以前的事了,但只是为了那些可能会寻找同样问题的人。
其实很简单(只要用图形类绘制你的精灵)。
1) 不灵活的孔切割:
这将创建一个 256 x 256 的矩形,其中有一个 64px 的孔。
2)灵活的孔切割:
显然,当您不使用图形类时,这将不起作用。在这种情况下,我会选择 BlendMode.ERASE。
使用 BlendMode.ERASE 时,您必须始终将父容器的混合模式设置为 BlendMode.LAYER,否则它将不起作用。
我希望这可以帮助某人
I know it's been a long time ago, but just for people who might look for the same problem.
It's actually quite easy (as long as draw your Sprite with the graphics class).
1) Inflexible hole cutting:
this will create a rectangle of 256 by 256 with a 64px hole in it.
2) Flexible hole cutting:
Obviously this will not work when you're not using the graphics class. In That case I would go with
BlendMode.ERASE
.When using BlendMode.ERASE you must ALWAYS set the parentcontainer's blendmode to BlendMode.LAYER, otherwise it won't work.
I hope this might help someone
如果我没记错的话,如果您在同一个图形上绘制两个重叠的对象而不停止填充,它们的工作方式将非常类似于 blendmode.erase。伪代码看起来像这样:
如果这确实有效(我想我多年前使用过这个解决方案,最近才看到 SVG 文件以这种方式工作),这应该会给你带来更好的性能。
编辑:我刚刚在我的一款游戏中使用了这个。
If I recall it correctly, if you draw two overlapping objects on the same graphics without stopping the fill, they will work pretty much like blendmode.erase. Pseudo-code would look like this:
If this actually works (and I think I used this solution many years ago and just recently saw that SVG files work this way), this should give you a much better performance.
EDIT: I have just used this myself in one of my games.
不是 AS 开发人员,但请看一下:http://code.google.com/p /gpcas/
这应该使您能够对两个多边形执行布尔“剪切”操作。
Not an AS developer, but take a look at this: http://code.google.com/p/gpcas/
This should enable you to do boolean "cutout" operations on two polygons.
好的,我想要的可以简单地完成,只需在半透明层上调用两次drawRect...一次绘制半透明矩形,再次绘制“洞”
详细信息在这里:
http://www.actionscript.org/forums/showthread.php3?p= 965632
不完全是一个面具,但足以满足我的目的。
OK, what I want can be done as simple as calling drawRect twice on the translucent layer...once to draw the translucent rectangle, and again to draw the "hole"
Details here:
http://www.actionscript.org/forums/showthread.php3?p=965632
Not exactly a mask, but good enough for my purposes.
看看这个方法,它允许一个可选的“hole”参数。这可以在 Flex 框架的 ProgrammaticSkin 类中找到。
http: //opensource.adobe.com/svn/opensource/flex/sdk/trunk/frameworks/projects/framework/src/mx/skins/ProgrammaticSkin.as
Check out this method, it allows for an optional "hole" parameter. This is found in the ProgrammaticSkin class of the flex framework.
http://opensource.adobe.com/svn/opensource/flex/sdk/trunk/frameworks/projects/framework/src/mx/skins/ProgrammaticSkin.as
如果有人需要梯度孔,可以使用 Raimundas 的技巧。假设您想要从内到外的椭圆渐变(内半径 alpha = 0,外半径 alpha = 1)。
首先绘制没有椭圆的背景
,然后在结果孔内绘制渐变椭圆!
椭圆将与孔完全匹配,像素完美。
In case someone needs to have a gradient hole, it's possible using trick from Raimundas. Let's say you want elliptical gradient coming from inside to the outside (inner radius alpha = 0, outer radius alpha = 1).
First draw the background without the ellipse
Then draw the gradient ellipse, inside the result hole!
The ellipse will match hole exactly, pixel-perfect.