VBfx / Tile tutorial / Step 2

Animation info

Before we can go on drawing animted tiles we need to have animated tiles. This will require 4 more variables in our tTile Type:

Public Type tTile
    'Tile info
    DC as Long
    'Animation setup
    FrameCount as Integer
    FrameDelay as Long
    'Animation data
    ActFrame as Integer
    NextTick as Long
    'Game properties
    Walkable as Boolean
End Type

As you can see I also re-ordered the properties to keep code structurized. Note that reordering may screw up your files, however I'll show you how to avoid this easily later. Since we're not working with tiles we don't have to care yet.

Well now that we added properties we also have to update the AddTile function so it can handle the number of animation frames and the delay for each tile. To make life easier I added another function called AddAnimTile, see code below:

Public Sub AddAnimTile( iDC as Long, iFrameCount as Integer, iFrameDelay as Long, iWalkable as Boolean )
    'Allocate memory
    TileCount = TileCount + 1
    ReDim Preserve Tile( TileCount )
    With Tile( TileCount )
        'Setup tile
        .DC = iDC
        'Setup animation info
        .FrameCount = iFrameCount
        .FrameDelay = iFrameDelay
        'Reset animation
        .ActFrame = 0
        .NextTick = 0
        'Setup game properties
        .Walkable = iWalkable
    End With
End Sub

It's nearly the same code as in AddTile, except that we have to pass the animation info (frame count and delay) that is applied to the new tile. Note that each tile can have it's own delay so animations can run asynchronously.