Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package actors
- {
- import flash.display.BitmapData;
- import flash.geom.Rectangle;
- /*
- * RotAnimSprite is a class designed to keep track of the properties of an animated sprite.
- * It does not do any actual animation on its own.
- */
- public class RotAnimSprite //rotatable animated sprite
- {
- private var _frameDelay:Vector.<int>; //flash frames per animation frame
- protected var _width:int; //width of an individual frame
- protected var _height:int; //height of an individual frame
- private var _angleSize:Number; //degrees per direction faced
- private var _dirCount:int; //number of different images, that compose a 360 degree rotation of the sprite
- private var _repeat:Boolean; //whether the animation repeats or not
- protected var _spriteSheet:BitmapData;
- public function RotAnimSprite(sheet:BitmapData, n:int, dirCount:int, rep:Boolean = false, delay:Vector.<int> = null)
- {
- if (!sheet) {
- throw new Error("sprite sheet BitmapData cannot be null.");
- }
- if (!delay) { //cannot declare objects in parameter initializer, as it is not a compile-time constant
- delay = new Vector.<int>();
- delay.push(3);
- }
- _spriteSheet = sheet;
- _width = n;
- _height = n;
- _dirCount = dirCount;
- _angleSize = 360 / dirCount;
- _repeat = rep;
- _frameDelay = delay;
- }
- public function get width():int {
- return _width;
- }
- public function get height():int {
- return _height;
- }
- public function get angleSize():Number {
- return _angleSize;
- }
- public function get dirCount():int {
- return _dirCount;
- }
- public function get spriteSheet():BitmapData {
- return _spriteSheet;
- }
- public function getFrameDelay(n:int):int {
- return _frameDelay[n];
- }
- public function getTotalFrames():int {
- return _frameDelay.length;
- }
- public function trash():void {
- _frameDelay = null;
- _width = 0;
- _height = 0;
- _angleSize = 0;
- _spriteSheet = null;
- //this = null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement