VBfx / Tile tutorial / Step 4

Drawing

We're already at the end of this extension so we're going to make our changes visible. As I told you at the beginning of this tutorial we only have to change the SourceX position to switch between animation frames. I copied the whole function again here, however only the selected line of the BitBlt call has changed:

Public Sub Draw()
    Dim X as Long
    Dim Y as Long
    
    Dim Index as Long
    Dim TileIndex as Long
    
    With Map
        'Calculate map index from the camera positon
        Index = ( Camera.Y * .w ) + Camera.X
        
        'Draw the map
        For Y = 0 To Camera.TilesY - 1
            For X = 0 To Camera.TilesX - 1
                'Get tile index
                TileIndex = .Data( Index )
                'Draw tile
                BitBlt Camera.FrontDC, _
                    X * TileSize, Y * TileSize, _
                    TileSize, TileSize, _
                    Tile( TileIndex ).DC, _
                    Tile( TileIndex ).ActFrame * TileSize, 0, _
vbSrcCopy 'Next tile Index = Index + 1 Next 'Get next line start Index = Index + .w - Camera.TilesX Next End With End Sub

See the difference? Instead of just blitting from 0, 0 we now use the current frame's position. We get this position by multiplicating the current frame number (ActFrame) by the tile size (TileSize).

Now we're done already and you can watch your animation (download the sample project below).

Where to go

We're done with simple animations here but there's still a lot of things you can do. You might want to add frame-individual timing and events, meaning that frame 1 is diplayed for 100 ms, frame 2 for 500 ms, and so on and in frame 3 some star particles are raised, just for example. This all gets more and more complicated and makes your Types growing fast, however.

Navigation