home *** CD-ROM | disk | FTP | other *** search
- package com.lofiminds.gm
- {
- import flash.display.BitmapData;
- import flash.geom.ColorTransform;
- import flash.geom.Matrix;
- import flash.geom.Point;
- import flash.geom.Rectangle;
-
- public final class GameImage
- {
-
-
- public var boundsHeight:int;
-
- public var width:Number;
-
- public var boundsHalfHeight:Number;
-
- public var boundsWidth:int;
-
- private var originalBitmap:BitmapData;
-
- public var boundsHalfWidth:Number;
-
- private var frames:Array;
-
- public var height:Number;
-
- public var frameCount:int;
-
- public var originX:Number;
-
- public var originY:Number;
-
- public function GameImage(param1:BitmapData, param2:int = 0, param3:int = 0, param4:int = 0, param5:int = 0)
- {
- super();
- this.originalBitmap = param1;
- this.width = param2 == 0 ? param1.width : param2;
- this.height = param3 == 0 ? param1.height : param3;
- this.boundsWidth = param4 == 0 ? int(this.width) : param4;
- this.boundsHeight = param5 == 0 ? int(this.height) : param5;
- this.boundsHalfWidth = boundsWidth * 0.5;
- this.boundsHalfHeight = boundsHeight * 0.5;
- setOrigin(Math.floor(width * 0.5),Math.floor(height * 0.5));
- initFrames();
- }
-
- public function colorTransform(param1:ColorTransform) : GameImage
- {
- var _loc3_:BitmapData = null;
- var _loc2_:int = 0;
- while(_loc2_ < this.frameCount)
- {
- _loc3_ = getFrame(_loc2_);
- _loc3_.colorTransform(_loc3_.rect,param1);
- _loc2_++;
- }
- return this;
- }
-
- public function flipVertical() : GameImage
- {
- var _loc4_:BitmapData = null;
- var _loc1_:BitmapData = new BitmapData(this.width,this.height,true,16777215);
- var _loc2_:Matrix = new Matrix();
- _loc2_.scale(1,-1);
- _loc2_.translate(0,this.height);
- var _loc3_:int = 0;
- while(_loc3_ < this.frameCount)
- {
- _loc4_ = getFrame(_loc3_);
- _loc1_.fillRect(_loc1_.rect,16777215);
- _loc1_.draw(_loc4_,_loc2_);
- _loc4_.fillRect(_loc4_.rect,16777215);
- _loc4_.copyPixels(_loc1_,_loc1_.rect,new Point(0,0));
- _loc3_++;
- }
- _loc1_.dispose();
- return this;
- }
-
- private function initFrames() : void
- {
- var _loc1_:Rectangle = null;
- var _loc2_:Point = null;
- var _loc3_:int = 0;
- var _loc4_:BitmapData = null;
- if(this.width == originalBitmap.width)
- {
- frameCount = 1;
- }
- else
- {
- frameCount = originalBitmap.width / width;
- frames = new Array();
- _loc1_ = new Rectangle(0,0,this.width,this.height);
- _loc2_ = new Point(0,0);
- _loc3_ = 0;
- while(_loc3_ < frameCount)
- {
- _loc4_ = new BitmapData(this.width,this.height);
- _loc1_.x = _loc3_ * this.width;
- _loc4_.copyPixels(originalBitmap,_loc1_,_loc2_);
- frames.push(_loc4_);
- _loc3_++;
- }
- }
- }
-
- public function clone() : GameImage
- {
- var _loc1_:BitmapData = originalBitmap.clone();
- var _loc2_:GameImage = new GameImage(_loc1_,width,height,boundsWidth,boundsHeight);
- _loc2_.setOrigin(this.originX,this.originY);
- return _loc2_;
- }
-
- public function setOrigin(param1:Number, param2:Number) : GameImage
- {
- originX = param1;
- originY = param2;
- return this;
- }
-
- final public function getFrame(param1:Number) : BitmapData
- {
- if(frames == null)
- {
- return originalBitmap;
- }
- return BitmapData(frames[int(param1)]);
- }
- }
- }
-