views:

104

answers:

1

It animates but it put's the piece of the sprite sheet where it is on the sprite sheet and not where the x and y tell it to. It's very short, so please take a look? Thank you in advance.

package cyanprime{
    import flash.display.*;
    import flash.geom.Rectangle;

    public class Player{
     [Embed(source="brownplane.png")]
     public var image:Class;
     public var bitmapdata:BitmapData = getBitmap(new image());
     public var bitmap:Bitmap = new Bitmap(bitmapdata);
     public var speed:int = 5;
     public var x:int = 50;
     public var y:int = 50;
     public var frame:int = 0;

     public function getBitmap(img:DisplayObject):BitmapData{
      var drawRect:Rectangle = new Rectangle((img.width/3) * frame, 0, img.width/3, img.height);
      var bitmap:BitmapData = new BitmapData(img.width, img.height);
      bitmap.draw(img,null,null,null,drawRect);
      return bitmap;
     }

     public function animate():void{
      bitmap.bitmapData = getBitmap(new image());
      frame++;

      if(frame > 2)
       frame = 0;

      bitmap.x = x;
      bitmap.y = y;
     }
    }
}
+1  A: 

Looks like you need to add a matrix transform to draw() to translate the position of the rectangle being drawn. Something like this:

var trans:Matrix = new Matrix();
trans.tx = drawRect.x;
bitmap.draw(img,trans,null,null,drawRect);

If that doesn't work, try -drawRect.x, I can't exactly remember how that transform is applied.

gb