Rendering of graphics different depending on 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 20:33 UTC
Read the original article Hit count: 217

Filed under:
|

When drawing parallel vertical lines with a fixed distance between them (1.75 pixels) with a non-integer x-value-offset to both lines, the lines are drawn differently based on the offset. 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.

alt text

Any ideas how ensure that sprites-with-non-integer-positions' graphics will visually display the same?

package
{

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

public class tmpa extends Sprite
{

private var _sp1:Sprite;
private var _sp2:Sprite;
private var _num:Number;

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

    _sp1 = new Sprite( );
    drawButt( _sp1, 0 );
    _sp1.x = 100;
    _sp1.y = 100;

    _num = 0;
    _sp2 = new Sprite( );
    drawButt( _sp2, _num );
    _sp2.x = 100;
    _sp2.y = 200;

    addChild( _sp1 );
    addChild( _sp2 );

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

private function efCb( evt:Event ):void
{   _num += .1;
    if (_num > 400)
    {   _num = 0;
    }
    drawButt( _sp2, _num );
}

private function drawButt( sp:Sprite, offset:Number ):void
{
    var px1:Number = 1 + offset;
    var px2:Number = 2.75 + offset;

    sp.graphics.clear( );
    sp.graphics.lineStyle( 1, 0, 1, true );
    sp.graphics.moveTo( px1, 1 );
    sp.graphics.lineTo( px1, 100 );

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

}
}

edit from original post which thought the problem was tied to the x-position of the sprite.

© Stack Overflow or respective owner

Related posts about actionscript-3

Related posts about flash