Add 'fake' antialiasing to rotated rectangle

柔情痞子 提交于 2019-12-22 09:33:56

问题


I'm using Corona SDK, which fairly recently disabled antialiasing, without a way to re-enable it. I have several apps that use rotated rectangles and lines, and would like a way for to not look jagged. This image shows the difference:

Is there a way to add some sort of antialiasing to these rectangles in Corona? I'd much prefer an antialias hack and be able to use new Corona features and fixes than use an old build with antialiasing.]

Thanks!


回答1:


You can use masks to your rects or images, it can minimize aliasing and it's a good alternative in anti-aliasing

I test the rect without a mask, it's ugly and when I added the mask it improved the rect

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

I used this mask, you can test it for yourself



来源:https://stackoverflow.com/questions/17539031/add-fake-antialiasing-to-rotated-rectangle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!