DrawRect is too big

This fairly simple drawing command creates a rendered 11x11 px red rectangle:

_sp.graphics.lineStyle( 1, 0xFF0000, 1, true, LineScaleMode.NORMAL, CapsStyle.NONE, JointStyle.MITER, 3 );
_sp.graphics.drawRect( 10, 10, 10, 10 );

      

What's the secret to creating 10x10 pixels?

If I fill a rectangle with the same drawRect parameters, it turns out 10x10 pixels:

_sp.graphics.beginFill( 0xFF0000, 1 );
_sp.graphics.drawRect( 10, 10, 10, 10 );
_sp.graphics.endFill( );

      

I would rather not drawRect (10, 10, 9, 9); as it looks like a hack.

+2


source to share


1 answer


When you draw a 10x10 rectangle, as in the second code snippet, Flash draws what you expect. But in your first snippet, you are drawing a vector edge around a 10x10 rectangle. In theory, Flash could fulfill this request by drawing a 12x12 edge that encloses a 10x10 rectangle, or draws a 10x10 rectangle that overlaps a 10x10 rectangle (thus enclosing an 8x8 rectangle). In practice, Flash breaks up the difference by selecting the shape's surround on two edges and overlapping it on the other two. But even then, if you start painting at half pixels and so on, you may find that the behavior differs subtly, since vector drawing is a tricky business and Flash rendering is highly optimized.



To control at the pixel level where the lines are drawn, you must draw them individually with moveTo()

and lineTo()

.

+3


source







All Articles