views:

691

answers:

3

Hi all! I'm using the AS3 drawRoundRect function as in the following snippet:

g.lineStyle(1, 0x808080, 1, true);
g.drawRoundRect(0, 0, 100, 24, 12, 12);

As you can see, pixel hinting is on.

The problem I'm having is corners being anti-aliased way too much, they are way too blurry and not even symmetrical on the above snippet. Frankly, the drawRoundRect function draws the ugliest rounded rectangles that I've ever seen.

Is there a way to make AS3 draw more crisp rectangles?

Thanks! :)

A: 

I've had similar problems in the past. It usually came down to one of the movieclips along the display path not being on an even pixel. Flash then tries to render fractional pixels, which it can't do, which caused distortion and blurriness.

So, make sure all your movieclips/sprites are on an even pixel (I know you're drawing the rect on even pixels, but if the displayobject it belongs to, or any of its parents aren't on an even pixel, it would be causing the problem).

Alex Jillard
I was making sure I'm drawing on even pixels, no values like 1.5 etc. I tried playing around with different values, but to no avail.
Joe Zephyr
+1  A: 

I've had the same deal, as well. One hacky trick you could try is to apply a minor blur filter to the parenting object.

It looks like you're using the drawRoundRect method of the Graphics class.

If the object you're working with is a UIComponent, you could try using the drawRoundRect method of UIComponent. It takes an Object for the cornerRadius value, rather than setting ellipse width and height values. I'm not 100% sure that the cornerRadius value isn't converted into ellipse width and height, but it seems like it'd be something to try.

Also, you could try the GraphicsUtil class's drawRoundRectComplex. It takes a Number for each corner's radius. Again, not completely sure that it doesn't eventually use the same underlying mechanics as drawRoundRect.

Ross Henderson
Your comment helped a lot, the drawRoundRectComplex function is at least, much more symmetrical than the other drawRoundRect.
Joe Zephyr
+1  A: 

fills are rendered much better than lines. as you can see here:

const thickness:Number = 1;
g.beginFill(0x080808);
g.drawRoundRect(0, 0, 100, 24, 12);
g.drawRoundRect(thickness, thickness, 100 - 2 * thickness, 24 - 2 * thickness, 12 - thickness);
g.endFill();
g.lineStyle(thickness, 0x080808, 1, true);
g.drawRoundRect(0, 50, 100, 24, 12);

well, it is not SOOOOOOOOOOO unincredibly better ... :-S ... but at least its symetric ... and the smudges on the corners are more like little beads ... :-D

back2dos
I used your trick with rhtx's drawRoundRectComplex function, overlaying the smaller rectangle over a slightly larger one, which serves as the border. It's not perfect, but at least looks a bit better.
Joe Zephyr