Corona Quick Thought – “cheap” antialiased lines

“Cheap” as in “it will work with Starter”. 😀 (on the other hand, if you have a Pro+ subscription, then you have access to other alternatives)

I was motivated to share this by a conversation started here, in the forum. Hope it’ll be helpful to someone somewhere.

One of the less-than-pretty things about Corona is that vector geometry is rendered aliased (those “jaggy edges” arising from not antialiasing .. and i will not antiapologize for using double-negatives).

But there are workarounds that might be suitable in certain instances, particularly if it’s just single line segments you’re after..

bitmap_lines_sample_output_zoomThose are 2X pixel zoom crops from actual output, vector lines on the left, bitmap lines on the right. Which do you prefer? (or click below for full image at 1X if you’d rather)
bitmap_lines_sample_output

The “trick” used here is to create the line segments using pre-rendered bitmaps. Bitmaps do render antialiased due to the bilinear texture sampling that occurs.

stroke4onmagenta
The bitmaps are just a single-pixel-wide portion of a line with the desired stroke width. (height of the bitmap is just whatever is necessary to fit the designed stroke width) For example, at left is a 4px stroke in a 1x8px bitmap, magnified 40X, against dark magenta to reveal transparency.

I’ll keep this short for now.. here’s a functional demo with code you can experiment with.

Look for the function named newBitmappedLine() within, read its docs, then see how used in the demonstration code later on.

Leave a Reply