Rendering of graphics different depending on DisplayObject position

Posted by jedierikb on Stack Overflow See other posts from Stack Overflow or by jedierikb
Published on 2010-04-13T18:30:51Z Indexed on 2010/04/13 18:33 UTC
Read the original article Hit count: 277

Filed under:
|

When drawing vertical lines with a non-integer x-value (e.g., 1.75) to a sprite, the lines are drawn differently based on the non-integer x-value of the sprite. In the picture below are two pairs of very close together vertical lines. As you can see, they look very different. This is frustrating, especially when animating the sprite.

some lines

Any ideas how ensure that sprites-with-non-integer-positions' graphics will visually display the same way regardless of the sprite position?

package
{

import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;

public class tmp extends Sprite
{

private var _sp1:Sprite;
private var _sp2:Sprite;

public function tmp( ):void
{
    stage.align = StageAlign.TOP_LEFT;
    stage.scaleMode = StageScaleMode.NO_SCALE;

    _sp1 = new Sprite( );
    drawButt( _sp1 );
    _sp1.x = 100;
    _sp1.y = 100;
    _sp2 = new Sprite( );
    drawButt( _sp2 );
    _sp2.x = 100;
    _sp2.y = 200;

    addChild( _sp1 );
    addChild( _sp2 );

    addEventListener( Event.ENTER_FRAME, efCb, false, 0, true );
}

private function efCb( evt:Event ):void
{   var nx:Number = _sp2.x + .1;
    if (nx > 400)
    {   nx = 100;
    }
    _sp2.x = nx;
}

private function drawButt( sp:Sprite ):void
{   sp.graphics.clear( );
    sp.graphics.lineStyle( 1, 0, 1, true );
    sp.graphics.moveTo( 1, 1 );
    sp.graphics.lineTo( 1, 100 );

    sp.graphics.lineStyle( 1, 0, 1, true );
    sp.graphics.moveTo( 1.75, 1 );
    sp.graphics.lineTo( 1.75, 100 );
}


}
}

© Stack Overflow or respective owner

Related posts about actionscript-3

Related posts about flash