A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: [RESOLVED] Stop Rounding to the Nearest Pixel

  1. #1
    Member
    Join Date
    May 2006
    Posts
    31

    resolved [RESOLVED] Stop Rounding to the Nearest Pixel

    My friend and I are working on a flash project in actionscript 3, and we are trying to move several movieclips by a portion of a pixel. Since we have filters on these movieclips, flash rounds their location to the nearest pixel, making the motion look jumpy. Is there anything that can be done to stop flash from rounding their location to the nearest pixel?

  2. #2
    newb of many sorts Ralgoth's Avatar
    Join Date
    Apr 2002
    Posts
    466
    as you said, using filters forces the movieclip to cacheAsBitmap, which in turn forces pixelSnapping.

    The only way around that I know of would be to draw the MovieClip to a bitmapData object, then set that to a new Bitmap object. Then you could set smoothing = true and PixelSnapping.NEVER on the Bitmap.
    Search first, asked questions later.

  3. #3
    newb of many sorts Ralgoth's Avatar
    Join Date
    Apr 2002
    Posts
    466
    well, that all sounded nice in theory. But I just tested it out to no avail.

    Code:
    var bitmapdata:BitmapData = new BitmapData(movieclip.width, movieclip.height);
    bitmapdata.draw(movieclip);
    removeChild(movieclip);
    
    var bitmap:Bitmap = new Bitmap(bitmapdata);
    bitmap.smoothing = true;
    bitmap.pixelSnapping = PixelSnapping.NEVER;
    addChild(bitmap);
    
    bitmap.addEventListener(Event.ENTER_FRAME, test);
    function test(e:Event):void
    {
    	e.target.x += .2;
    }
    Search first, asked questions later.

  4. #4
    newb of many sorts Ralgoth's Avatar
    Join Date
    Apr 2002
    Posts
    466
    heh, so I guess I just needed to take my head away from the monitor. It's working fine

    Here's the bit you'll need...

    Code:
    var bd:BitmapData = new BitmapData(mc.width,mc.height);
    bd.draw(mc);
    removeChild(mc);
    var bmp:Bitmap = new Bitmap(bd, PixelSnapping.NEVER, true);
    addChild(bmp);
    Also, if you're using any filters that extend the size of the mc, make sure you compensate for the additional size.
    Search first, asked questions later.

  5. #5
    Member
    Join Date
    May 2006
    Posts
    31
    Thank you for trying to help us. We are trying to implement the code you gave us, but we were working with DisplayObjects so we had to change our code to use movieclips instead. Anyway, we got that part working, but the actual bitmaps aren't being drawn correctly. The bitmap is appearing as a white rectangle. In the upper left hand corner of that rectangle, the lower right hand corner of our movieclip is shown.

    Do you know why the bitmaps aren't being drawn properly?

  6. #6
    newb of many sorts Ralgoth's Avatar
    Join Date
    Apr 2002
    Posts
    466
    By default, the draw() command is going to start at the 0,0 coordinate. You'll need to offset that using a matrix...
    PHP Code:
    // Use padding to compensate for filters that increase the overall mc size, like glow or dropshadow.
    var PADDING:Number 20;
    // add padding to the width and height
    var WIDTH:Number mc.width+PADDING;                    
    var 
    HEIGHT:Number mc.height+PADDING;
    // create the bitmapdata object with the padded size
    var bd:BitmapData = new BitmapData(WIDTH,HEIGHT);
    // draw command starts at 0,0 by default
    // assuming your clip is center aligned, we change the starting coordinates to -width/2,-height/2
    var matx:Matrix = new Matrix(1,0,0,1,WIDTH/2,HEIGHT/2);
    // add the matrix to the draw method
    bd.draw(mc,matx);
    // create the bitmap with our new bitmapdata
    var bmp:Bitmap = new Bitmap(bdPixelSnapping.NEVERtrue);
    // out with the old
    removeChild(mc);
    // in with the new
    addChild(bmp); 
    Search first, asked questions later.

  7. #7
    Member
    Join Date
    May 2006
    Posts
    31
    Thank you very much. Our problem was fixed.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center