VBfx / Tile tutorial / Step 4

Loading resources

The final step is to load the resources after loading the level data. We have to do this because we only stored the file names and not the corresponding graphics. The function simply loads the graphics for each tile and sets the Bitmap index:

Public Sub LoadResources()
    Dim A as Long
    
    For A = 1 To TileCount
        'Load the bitmap and get it's index
        Tile( A ).Bitmap = mBitmap.LoadBitmap( App.Path & "\SOURCE\" & Tile( A ).PictureFile )
    Next
End Sub

This function only has to be called after loading the map. You could even call it from mMap.LoadData directly, it's your decision whether to keep code more flexible or more automated. In the demo project I placed it in the button, the code looks like this:

Private Sub cmdLoad_Click()
    'Call load function
    mMap.LoadData App.Path & "\Test.map"
    
    'Now that we loaded the tiles, load the pictures for them
    mTiles.LoadResources
End Sub

Conclusion

Finally we made it through this extension and we can now save the map into a file and load it back later, even after rebooting. You should now be able to create functions for writing and reading data and decide which data has to be stored there.

In the demo project I included a mini-editor so you can see that it really works, just click on the map to change the tiles. Moving the camera is now done by holding the right mouse button by the way.

Navigation