rorypicko
rorypicko

Reputation: 4234

AS3 BitmapData Copy Pixels Half Pixel?

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?

Upvotes: 0

Views: 1092

Answers (1)

Plastic Sturgeon
Plastic Sturgeon

Reputation: 12527

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

Upvotes: 1

Related Questions