Advertisement
Guest User

Untitled

a guest
Mar 6th, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package actors
  2. {
  3.     import flash.display.BitmapData;
  4.     import flash.geom.Rectangle;
  5.    
  6.     /*
  7.      * RotAnimSprite is a class designed to keep track of the properties of an animated sprite.
  8.      * It does not do any actual animation on its own.
  9.      */
  10.     public class RotAnimSprite //rotatable animated sprite
  11.     {
  12.         private var _frameDelay:Vector.<int>; //flash frames per animation frame
  13.        
  14.         protected var _width:int;  //width of an individual frame
  15.         protected var _height:int; //height of an individual frame
  16.         private var _angleSize:Number; //degrees per direction faced
  17.         private var _dirCount:int; //number of different images, that compose a 360 degree rotation of the sprite
  18.         private var _repeat:Boolean; //whether the animation repeats or not
  19.        
  20.         protected var _spriteSheet:BitmapData;
  21.        
  22.         public function RotAnimSprite(sheet:BitmapData, n:int, dirCount:int, rep:Boolean = false, delay:Vector.<int> = null)
  23.         {
  24.             if (!sheet) {
  25.                 throw new Error("sprite sheet BitmapData cannot be null.");
  26.             }
  27.             if (!delay) { //cannot declare objects in parameter initializer, as it is not a compile-time constant
  28.                 delay = new Vector.<int>();
  29.                 delay.push(3);
  30.             }
  31.             _spriteSheet = sheet;
  32.             _width = n;
  33.             _height = n;
  34.             _dirCount = dirCount;
  35.             _angleSize = 360 / dirCount;
  36.             _repeat = rep;
  37.            
  38.             _frameDelay = delay;
  39.         }
  40.        
  41.         public function get width():int {
  42.             return _width;
  43.         }
  44.         public function get height():int {
  45.             return _height;
  46.         }
  47.         public function get angleSize():Number {
  48.             return _angleSize;
  49.         }
  50.         public function get dirCount():int {
  51.             return _dirCount;
  52.         }
  53.         public function get spriteSheet():BitmapData {
  54.             return _spriteSheet;
  55.         }
  56.        
  57.         public function getFrameDelay(n:int):int {
  58.             return _frameDelay[n];
  59.         }
  60.         public function getTotalFrames():int {
  61.             return _frameDelay.length;
  62.         }
  63.        
  64.         public function trash():void {
  65.             _frameDelay = null;
  66.             _width = 0;
  67.             _height = 0;
  68.             _angleSize = 0;
  69.             _spriteSheet = null;
  70.             //this = null;
  71.         }
  72.        
  73.     }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement