home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Diversos / xwung.swf / scripts / com / lofiminds / gm / GameImage.as < prev    next >
Encoding:
Text File  |  2008-09-03  |  4.0 KB  |  136 lines

  1. package com.lofiminds.gm
  2. {
  3.    import flash.display.BitmapData;
  4.    import flash.geom.ColorTransform;
  5.    import flash.geom.Matrix;
  6.    import flash.geom.Point;
  7.    import flash.geom.Rectangle;
  8.    
  9.    public final class GameImage
  10.    {
  11.        
  12.       
  13.       public var boundsHeight:int;
  14.       
  15.       public var width:Number;
  16.       
  17.       public var boundsHalfHeight:Number;
  18.       
  19.       public var boundsWidth:int;
  20.       
  21.       private var originalBitmap:BitmapData;
  22.       
  23.       public var boundsHalfWidth:Number;
  24.       
  25.       private var frames:Array;
  26.       
  27.       public var height:Number;
  28.       
  29.       public var frameCount:int;
  30.       
  31.       public var originX:Number;
  32.       
  33.       public var originY:Number;
  34.       
  35.       public function GameImage(param1:BitmapData, param2:int = 0, param3:int = 0, param4:int = 0, param5:int = 0)
  36.       {
  37.          super();
  38.          this.originalBitmap = param1;
  39.          this.width = param2 == 0 ? param1.width : param2;
  40.          this.height = param3 == 0 ? param1.height : param3;
  41.          this.boundsWidth = param4 == 0 ? int(this.width) : param4;
  42.          this.boundsHeight = param5 == 0 ? int(this.height) : param5;
  43.          this.boundsHalfWidth = boundsWidth * 0.5;
  44.          this.boundsHalfHeight = boundsHeight * 0.5;
  45.          setOrigin(Math.floor(width * 0.5),Math.floor(height * 0.5));
  46.          initFrames();
  47.       }
  48.       
  49.       public function colorTransform(param1:ColorTransform) : GameImage
  50.       {
  51.          var _loc3_:BitmapData = null;
  52.          var _loc2_:int = 0;
  53.          while(_loc2_ < this.frameCount)
  54.          {
  55.             _loc3_ = getFrame(_loc2_);
  56.             _loc3_.colorTransform(_loc3_.rect,param1);
  57.             _loc2_++;
  58.          }
  59.          return this;
  60.       }
  61.       
  62.       public function flipVertical() : GameImage
  63.       {
  64.          var _loc4_:BitmapData = null;
  65.          var _loc1_:BitmapData = new BitmapData(this.width,this.height,true,16777215);
  66.          var _loc2_:Matrix = new Matrix();
  67.          _loc2_.scale(1,-1);
  68.          _loc2_.translate(0,this.height);
  69.          var _loc3_:int = 0;
  70.          while(_loc3_ < this.frameCount)
  71.          {
  72.             _loc4_ = getFrame(_loc3_);
  73.             _loc1_.fillRect(_loc1_.rect,16777215);
  74.             _loc1_.draw(_loc4_,_loc2_);
  75.             _loc4_.fillRect(_loc4_.rect,16777215);
  76.             _loc4_.copyPixels(_loc1_,_loc1_.rect,new Point(0,0));
  77.             _loc3_++;
  78.          }
  79.          _loc1_.dispose();
  80.          return this;
  81.       }
  82.       
  83.       private function initFrames() : void
  84.       {
  85.          var _loc1_:Rectangle = null;
  86.          var _loc2_:Point = null;
  87.          var _loc3_:int = 0;
  88.          var _loc4_:BitmapData = null;
  89.          if(this.width == originalBitmap.width)
  90.          {
  91.             frameCount = 1;
  92.          }
  93.          else
  94.          {
  95.             frameCount = originalBitmap.width / width;
  96.             frames = new Array();
  97.             _loc1_ = new Rectangle(0,0,this.width,this.height);
  98.             _loc2_ = new Point(0,0);
  99.             _loc3_ = 0;
  100.             while(_loc3_ < frameCount)
  101.             {
  102.                _loc4_ = new BitmapData(this.width,this.height);
  103.                _loc1_.x = _loc3_ * this.width;
  104.                _loc4_.copyPixels(originalBitmap,_loc1_,_loc2_);
  105.                frames.push(_loc4_);
  106.                _loc3_++;
  107.             }
  108.          }
  109.       }
  110.       
  111.       public function clone() : GameImage
  112.       {
  113.          var _loc1_:BitmapData = originalBitmap.clone();
  114.          var _loc2_:GameImage = new GameImage(_loc1_,width,height,boundsWidth,boundsHeight);
  115.          _loc2_.setOrigin(this.originX,this.originY);
  116.          return _loc2_;
  117.       }
  118.       
  119.       public function setOrigin(param1:Number, param2:Number) : GameImage
  120.       {
  121.          originX = param1;
  122.          originY = param2;
  123.          return this;
  124.       }
  125.       
  126.       final public function getFrame(param1:Number) : BitmapData
  127.       {
  128.          if(frames == null)
  129.          {
  130.             return originalBitmap;
  131.          }
  132.          return BitmapData(frames[int(param1)]);
  133.       }
  134.    }
  135. }
  136.