Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This question was asked a while ago, but since it has remained unanswered I'll add my two cents. </p> <p>I just had to figure this out for a project I'm working on and came up with the following solution. The general idea is to draw the bitmap into the graphics of a display object and to use a matrix transform to control the x and y coords of a viewport over the bitmap data.</p> <pre><code>public class Example extends Sprite { private var vx:Number; private var vy:Number; private var coords:Point; private var shape:Shape; private var bitmap:Bitmap; private var bmd:BitmapData; public function Example() { vx = 1.5; vy = -3.0; coords = new Point(); shape = new Shape(); bitmap = new Image(); // image, in my case is an embedded image bmd = bitmap.bitmapData; addChild(shape); addEventListener(Event.ENTER_FRAME, onEnterFrame); } private function onEnterFrame(event:Event):void { coords.x += vx; coords.y += vy; // this is important! // without it, bitmap size constraints are reached and scrolling stops coords.x %= bitmap.width; coords.y %= bitmap.height; shape.graphics.clear(); shape.graphics.beginBitmapFill(bmd, new Matrix(1, 0, 0, 1, coords.x, coords.y), true, true); shape.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight); shape.graphics.endFill(); } } </code></pre> <p>Now you can just update the x &amp; y values of the Point object to scroll around the bitmap. You can easily add velocity, acceleration and friction to the equation to make the scrolling more dynamic.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload