Animated tiles in Flixel

Animated tiles in Flixel

I managed to get animated tiles working for a game I am developing in Flixel. The method I have used is not very efficient: the program loops through all the tiles in the tilemap and changes the tile if it is an animated tile.

In the future I might improve this method if it creates to much lag. One way it can be improved is to have a list of tiles that should be updated, so the loop will only run on the necessary tiles. The list can be created by running the loop on all the tiles one time.

override public function update():void
{
    for (var i:int = 0; i < _tilemap.totalTiles; i++)
    {
        if (_tilemap.getTileByIndex(i) == 1)
        {
            _tilemap.setTileByIndex(i, 2);
        }
        else if (_tilemap.getTileByIndex(i) == 2)
        {
            _tilemap.setTileByIndex(i, 1);
        }
    }
    super.update();
}

In the snippet above, tile id 1 and 2 are the indexes of the two wave tiles in the tilesheet.

Leave a comment

Your email address will not be published.