You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've written a class that extends FlxTilemap. Its really useful if you have an animated tileset that you want to use for say a top down strategy game. Feel free to use it and change the opening comment to be licensed however you want.
I've called it 'FlxAnimatedTilemap.as' in my branch.
packageorg.flixel
{
import org.flixel.FlxTilemap;/*** Extention of FlxTileMap that allows for loading in several images and swaping them to animate.* * @author Michael Silverman*/publicclassFlxAnimatedTilemapextendsFlxTilemap
{
/*** Internal list of the frames in the tilemap animation.*/protectedvar_tileArray:Array;/*** Internal current index in the animation array.*/protectedvar_curFrame:uint;/*** Internal, used to time each frame of animation.*/protectedvar_frameTimer:Number;/*** Internal, length of each frame*/protectedvar_frameTime:Number;/*** The tilemap constructor just initializes some basic variables.*/publicfunctionFlxAnimatedTilemap()
{
super();_tileArray=newArray();_curFrame=0;_frameTimer=0;_frameTime=0.125;
}
/*** Clean up memory.*/overridepublicfunctiondestroy():void
{
for (var i:uint=0; i <_tileArray.length; i++ )
{
_tileArray[i]=null;
}
_tileArray=null;super.destroy();
}
publicfunctionloadAnimatedMap(MapData:String, TileArray:Array, TileWidth:uint=0, TileHeight:uint=0, AutoTile:uint=OFF, StartingIndex:uint=0, DrawIndex:uint=1, CollideIndex:uint=1, FrameTime:Number=0.125):FlxAnimatedTilemap
{
super.loadMap(MapData, TileArray[0], TileWidth, TileHeight, AutoTile, StartingIndex, DrawIndex, CollideIndex);_tileArray=newArray();for (var i:uint=0; i < TileArray.length; i++)
{
_tileArray.push(FlxG.addBitmap(TileArray[i]));
}
_frameTime= FrameTime;returnthis;
}
/*** Automatically called after update() by the game loop,* this function swaps the tile image if needed.*/overridepublicfunctionpostUpdate():void
{
super.postUpdate();var dirty:Boolean;if (_tileArray.length >0)
{
_frameTimer+= FlxG.elapsed;while(_frameTimer>_frameTime)
{
_frameTimer=_frameTimer-_frameTime;if(_curFrame==_tileArray.length-1)
{
_curFrame=0;
}
else_curFrame++;_tiles=_tileArray[_curFrame];
dirty =true;
}
}
if (dirty)
{
setDirty(true);
}
}
}
}
The text was updated successfully, but these errors were encountered:
I've written a class that extends FlxTilemap. Its really useful if you have an animated tileset that you want to use for say a top down strategy game. Feel free to use it and change the opening comment to be licensed however you want.
I've called it 'FlxAnimatedTilemap.as' in my branch.
The text was updated successfully, but these errors were encountered: