Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package icarus.util
- {
- import flash.geom.Rectangle;
- import org.flixel.*;
- /**
- * This allows you to define per-tile animations for a tilemap.
- * These are done via a FlxSprite instance so that you can manipulate
- * it as much as you like.
- */
- public class AnimatedTilemap extends FlxTilemap
- {
- public var sprites:Array;
- protected var lastFrames:Array;
- protected var tileRect:Rectangle;
- public function AnimatedTilemap()
- {
- super();
- this.tileRect = new Rectangle();
- this.tileRect.x = 0;
- this.tileRect.y = 0;
- }
- override public function loadMap(MapData:String, TileGraphic:Class, TileWidth:uint = 0, TileHeight:uint = 0):FlxTilemap
- {
- super.loadMap(MapData, TileGraphic, TileWidth, TileHeight);
- this.sprites = [];
- this.lastFrames = [];
- this.tileRect.width = this._tileWidth;
- this.tileRect.height = this._tileHeight;
- return this;
- }
- override public function update():void
- {
- for (var i:int = 0; i < this.sprites.length; i++)
- if (this.sprites[i] is FlxSprite)
- (this.sprites[i] as FlxSprite).update();
- super.update();
- }
- override public function render():void
- {
- this._flashPoint.y = 0;
- for (var i:int = 0; i < this.sprites.length; i++)
- if (this.sprites[i] is FlxSprite)
- {
- var sprite:FlxSprite = this.sprites[i] as FlxSprite;
- // if the sprite's frame changed, paint it onto our pixels
- if (sprite.frame != this.lastFrames[i] || true)
- {
- this._flashPoint.x = i * this._tileWidth;
- this._pixels.copyPixels(sprite._framePixels, this.tileRect, this._flashPoint);
- this.lastFrames[i] = sprite.frame;
- }
- }
- super.render();
- }
- }
- }
Add Comment
Please, Sign In to add comment