Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionScript drawRoundRect rendering inconsistent corner radii

I'm trying to draw a shape with quite precise rounded corners, I'd settle for anything around 3px. Unfortunately Flash has other ideas, and is creating a rounded rectangle with four seemingly different radii. My code is below:

var sq:Shape = new Shape();
sq.graphics.beginFill(0x000000,1);
sq.graphics.drawRoundRect(20,20,20,20,4,4);
sq.graphics.endFill();
addChild(drop);

I removed the line as apparently fills render better, and changed to an even number radius as apparently that helps, but it's still the same. The code above gives me a square like so:

Zoomed in view of sqaure

The corners are noticeably different. If I were using a bigger radius it might not be so much of a problem, but because of the small radius of the corners the square just looks odd.

Have I missed the drawRoundRectEvenly function or am I asking too much here? Any help is appreciated! Thanks!

Darren

like image 558
frontendbeast Avatar asked Feb 22 '26 00:02

frontendbeast


1 Answers

Try setting pixelHinting to true.

sq.graphics.lineStyle(1, 0x000000, 1.0, true); 

Even if you're not using strokes, try it with an alpha 0 and see if it helps smooth things a bit. It will most likely still not be perfect, but it should snap to pixels a bit better and clean up dramatically.

like image 63
James Tomasino Avatar answered Feb 25 '26 14:02

James Tomasino



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!