I am trying to animate a tilemap using Flixel 2.55. I found this code that apparently enables the use of sprites as tiles.

To my understanding, this loops over the tilemap's graphic and replaces the tile's pixels with the sprite's pixels each time they change. I have implemented the class and it's working, but not completely; the tiles get replaced, but do not animate unless the camera moves. Here's is the relevant part from LevelLoader.as, which only instantiates the AnimatedTilemaps (piece of code from forum) and pushes sprites into an array:

// AnimatedTile is just an extended FlxSprite
private var _waterTop1:AnimatedTile;

// Create ground tilemap
_groundTilemap = new AnimatedTilemap();
_groundTilemap.loadMap(_rawXML.Ground, Assets.OverworldGround, 8, 8);

_waterTop1 = new AnimatedTile(8, 8, Assets.WaterTop, 100);
// .Animate only adds and plays an animation, with a startAtFrame param.
_waterTop1.Animate('run', [0...47], 10, true, 0);

It seems as though the sprites are updating. I tried tracing the update()s, and they are running for both the sprites and the tilemap. The sprites are even changing frames. Using only AnimatedTiles and hard-placing them (giving a x and y) works and animates. What troubles me is that they only update when the camera moves.

I've been stuck on this for a week now. I am also open to other solutions for animating tilemap tiles.


1 Answer 1


You might need to mark the buffer as "dirty". Looks like you can do this via setDirty().

These threads touch on "dirty" a bit:

My understanding is that Flixel has some optimizations that pre-compute values for drawing and it will only recompute them when the "dirty" flag is set. In your case moving the camera is probably marking the tilemap as "dirty", hence it updates when the camera moves.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .