Animated tiles
I''m currently in the middle of the development of a 2D top-down tile engine and I came across the problem of sychronizing the animation of the tiles. What I mean: if I update the animation frames of only those tiles that are currently visible, the tiles outside the current view are not animated and when they become visible they are not synchronized with others.
On the other hand, if I always animate all of the tiles the frame rate drops considerably.
Any ideas on how to solve this?
Currently I''m using secs per frame to animate tiles - maybe I should switch from deltas to real time and update tiles accordingly, but somehow it doesn''t seem right.
I wrote the BMDXCtls 2-D tile engine and handled it like this. I have a tile mapping that maps each map tile value to a tileset index value. By default this mapping is straight accross. That is, a map index of 23 will display tile number 23 when the map is drawn. To animate a tile I simply update the mapping. This automatically "animates" all tiles of that value on the map. This works best when your tilespace is small. For instance, I only allow 256 tile values (one byte per tile on the map). That means my mapping object only needs 256 bytes. A tile mapping array of 65k wouldn''t be too bad though (if your tiles are 2-byte indexes). The amount of extra CPU work involved in the one extra level of indirection is insignificant next to the work involved in the rest of the process of redrawing the display.
If you''d like to see BMDXCtls or the Scrolling Game Development in which BMDXCtls is used, visit http://gamedev.sf.net/ (no affiliation with gamedev.net).
"All you need to do to learn circular logic is learn circular logic"
"All you need to do to learn circular logic is learn circular logic"
If the animations of the same tiles are going to be syncronized, why not just update the animation for each type of tile instead of each individual tile?
Thanx for the replays.
Well, in my engine I decouple the tile image data from the animation parameters and the tile flags. This way each tile on the map has its own parameters and a pointer to the image data array.
In a previous version I had the map structure exactly like you describe i.e. indices into a tileset. The tiles were synchronized because they shared the same animation parametes(current frame, speed etc.), but I tought to give the engine some more flexibility.
I''m sure there''s a nice way to do it.
Well, in my engine I decouple the tile image data from the animation parameters and the tile flags. This way each tile on the map has its own parameters and a pointer to the image data array.
In a previous version I had the map structure exactly like you describe i.e. indices into a tileset. The tiles were synchronized because they shared the same animation parametes(current frame, speed etc.), but I tought to give the engine some more flexibility.
I''m sure there''s a nice way to do it.
I cheat.
Organize your animated tiles so the frames are vertical or horizontal.
Have a global frame counter say, CurrFrame which is incremented every frame and modded by the max number of frames regardless of what''s going on. Use CurrFrame to determine what frame of animation the tile is on. That way you don''t have ot change the tile value in the map.
CurrFrame++;
CurrFrame%=8;
tile.left=CurrFrame*32;
tile.right=tile.left+32;
tile.top=Tile[Map[y][x].tile].tilesurfy;
tile.bottom=tile.top+32;
BlitFast(ScreenX,ScreenY,&tile,...);
You get the idea. You just need a way to tell the difference between an animated an non animated tile.
Ben
The Rabbithole
Organize your animated tiles so the frames are vertical or horizontal.
Have a global frame counter say, CurrFrame which is incremented every frame and modded by the max number of frames regardless of what''s going on. Use CurrFrame to determine what frame of animation the tile is on. That way you don''t have ot change the tile value in the map.
CurrFrame++;
CurrFrame%=8;
tile.left=CurrFrame*32;
tile.right=tile.left+32;
tile.top=Tile[Map[y][x].tile].tilesurfy;
tile.bottom=tile.top+32;
BlitFast(ScreenX,ScreenY,&tile,...);
You get the idea. You just need a way to tell the difference between an animated an non animated tile.
Ben
The Rabbithole
quote:
Original post by KalvinB
Have a global frame counter say, CurrFrame which is incremented every frame and modded by the max number of frames regardless of what''s going on. Use CurrFrame to determine what frame of animation the tile is on. That way you don''t have ot change the tile value in the map.
That''s how I used BMDXCtls in the Scrolling Game Development Kit too. And if you need more animations, as suggested by your comment on flexibility, just add a new type of tile with its own animation sequence.
Some terminology before I finish this post:
- Tile = a value from the map, in my case a value from 0 to 255, indicating what is at this location on the map.
- Frame = A graphic from a tileset (an index into the tileset) that indicates an image that can be used to represent the display of a map tile in the current state.
In my case, Tiles and Frames are closely tied together, they have the same range (0 to 255) and, for non-animated tiles, they use identical values. So in my case it was very simple. Every tile on the map (by default) acts as an indirect index into the tileset (to a frame). Each tile value that could be placed on the map was either animated or not (as dictated by my AnimDefs collection). If there was an AnimDef for the specified tile index, that tile would animate according to the frames defined in the AnimDef. Otherwise the tile would simply be drawn according to its index (frame=tile). If I want a tile representing a flickering fire, I draw 5 frames representing the fire''s animation. (This also occupies 5 tile slots in my architecture.) Then I crete an AnimDef that animates the first of those 5 tiles using the 5 frames. The other 4 tiles are open to be animated in different ways or to be left un-animated (the frame indexes are already used but the tile indexes are not).
"All you need to do to learn circular logic is learn circular logic"
"All you need to do to learn circular logic is learn circular logic"
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement