Guest User

Untitled

a guest
Oct 29th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package icarus.util
  2. {
  3.     import flash.geom.Rectangle;
  4.     import org.flixel.*;
  5.    
  6.     /**
  7.      * This allows you to define per-tile animations for a tilemap.
  8.      * These are done via a FlxSprite instance so that you can manipulate
  9.      * it as much as you like.
  10.      */
  11.    
  12.     public class AnimatedTilemap extends FlxTilemap
  13.     {
  14.         public var sprites:Array;
  15.         protected var lastFrames:Array;
  16.         protected var tileRect:Rectangle;
  17.        
  18.         public function AnimatedTilemap()
  19.         {
  20.             super();
  21.             this.tileRect = new Rectangle();
  22.             this.tileRect.x = 0;
  23.             this.tileRect.y = 0;
  24.         }
  25.        
  26.         override public function loadMap(MapData:String, TileGraphic:Class, TileWidth:uint = 0, TileHeight:uint = 0):FlxTilemap
  27.         {
  28.             super.loadMap(MapData, TileGraphic, TileWidth, TileHeight);
  29.             this.sprites = [];
  30.             this.lastFrames = [];
  31.             this.tileRect.width = this._tileWidth;
  32.             this.tileRect.height = this._tileHeight;
  33.             return this;
  34.         }
  35.        
  36.         override public function update():void
  37.         {
  38.             for (var i:int = 0; i < this.sprites.length; i++)
  39.                 if (this.sprites[i] is FlxSprite)
  40.                     (this.sprites[i] as FlxSprite).update();
  41.            
  42.             super.update();
  43.         }
  44.        
  45.         override public function render():void
  46.         {                                  
  47.             this._flashPoint.y = 0;
  48.            
  49.             for (var i:int = 0; i < this.sprites.length; i++)
  50.                 if (this.sprites[i] is FlxSprite)
  51.                 {
  52.                     var sprite:FlxSprite = this.sprites[i] as FlxSprite;
  53.  
  54.                     // if the sprite's frame changed, paint it onto our pixels
  55.                    
  56.                     if (sprite.frame != this.lastFrames[i] || true)
  57.                     {
  58.                         this._flashPoint.x = i * this._tileWidth;
  59.                         this._pixels.copyPixels(sprite._framePixels, this.tileRect, this._flashPoint);
  60.                         this.lastFrames[i] = sprite.frame;
  61.                     }
  62.                 }
  63.            
  64.             super.render();
  65.         }
  66.     }
  67. }
Add Comment
Please, Sign In to add comment