给旋转矩形添加“伪”抗锯齿

3
我正在使用Corona SDK,它最近禁用了抗锯齿功能,没有重新启用的方法。我的几个应用程序使用旋转矩形和线条,我希望能够让它们看起来不那么锯齿。这张图片展示了区别:enter image description here 有没有办法在Corona中为这些矩形添加某种抗锯齿效果?我更喜欢一种抗锯齿的方法,并能够使用新的Corona特性和修复,而不是使用带有抗锯齿的旧版本。
谢谢!
1个回答

1
你可以在矩形或图片中使用遮罩,它可以最小化锯齿,并且是反锯齿的良好替代方法。
我测试了没有遮罩的矩形,很难看,但当我添加了遮罩时,矩形变得更好看了。
display.newRect(0,0,320,480) --Background

local rmask = graphics.newMask( "mask.png" ) --Mask

local w = math.random(100,300) --Your random width of your rect
local h = math.random(100,300) --Your random height of your rect
local r = display.newRect(100,100,w,h) --Rect
r:setFillColor(0,0,0)
r:setMask(rmask)

--This will resize the mask to your rect's dimensions, make sure you know your mask's width and height
r.maskScaleX = w/200 --the 200 is the mask's width
r.maskScaleY = h/200 --the 200 is the mask's height

transition.to(r,{time = 100000, rotation = 360*10}) --To test the aliasing when it rotates

我用了这个口罩,你可以自己测试一下

200x200 mask


这绝对是一个有趣的想法,我可以看到它确实减少了别名效应。有办法动态生成掩模吗?(可能没有,但我的应用程序中的矩形可以是任意随机尺寸,为每个尺寸创建和包含掩模图像将是不可行的。) - penguinrob
你可以动态生成遮罩或图像,我发现可以通过使用display.save()实现,这将把一个显示组保存为图像,然后你可以将保存的图像用作遮罩。http://docs.coronalabs.com/api/library/display/save.html - NaviRamyle
我之前不知道你可以这样做,这真的很好知道。为每个矩形大小生成一个遮罩、保存并应用它听起来需要消耗很多资源。但也许这是最好的选择。 - penguinrob
这是一个很好的解决方案,我只是在尝试弄清楚如何让它适用于小矩形和大矩形。我想我会有一个小掩码和一个大掩码。 - penguinrob
是的,你可以这样做,我很高兴能帮助你,同时我也学到了一些东西。 - NaviRamyle
有没有同时激活3个掩码的限制? - JohnGB

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接