0
votes

Having trouble trying to scroll BitmapData on a half pixel here is my original code

var speed:Number = 1;
_bitmapData.copyPixels(_backgroundParallax, _screenRect, _zeroPoint, null, null, true);
_backgroundParallax.copyPixels(_backgroundParallax, new Rectangle(0, 0, speed,    _backgroundParallax.height), new Point(_backgroundParallax.width-speed,0), null, null, false);
_backgroundParallax.scroll( (speed*-1) , 0);

which works until i change the var speed to .5, which is because .scroll method is expecting int's so i replicated what scroll is doing to try and allow .5 pixels

var speed:Number = 1;
_bitmapData.copyPixels(_backgroundParallax, _screenRect, _zeroPoint, null, null, true);
_backgroundParallax.copyPixels(_backgroundParallax, new Rectangle(0, 0, speed,    _backgroundParallax.height), new Point(_backgroundParallax.width-speed,0), null, null, false);
_backgroundParallax.copyPixels(_backgroundParallax, new Rectangle(0, 0, _backgroundParallax.width, _backgroundParallax.height), new Point((speed*-1),0), null, null, false);

which again works great when the speed is 1, but again doesn't move at all when it is set to .5

Any ideas?

1
unfortunately for pixels there is no half size. maybe you can use some math to slow down things. - Adrian Pirvulescu
Are you trying to call this code multiple times to scroll the bitmap, but want to slow the execution speed? - sch
@sch this code is running on the enterframe - rorypicko
@AdrianPirvulescu Thought so! I'll slow it down by other means. Cheers - rorypicko

1 Answers

1
votes

You won't be able to get smooth half-pixel scrolling with the approach you are using. But I have developed two alternatives using transform matrix that work really really well.

Here are two different approaches to scrolling:

This approach scrolls a single image to its limits. http://plasticsturgeon.com/2010/11/super-fast-scrolling-of-huge-bitmaps/

This approach scrolls a tiled image infinitely. http://plasticsturgeon.com/2010/06/infinite-scrolling-bitmap-backgrounds-in-as3/

Working demos, explanation and complete downloadable source code provided on the links