kcnhgames.com header

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.

This entry was posted in Game development, Tutorials and tagged , , , , , , . Bookmark the permalink. Follow any comments here with the RSS feed for this post. Post a comment or leave a trackback: Trackback URL.


Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>