# Visual Basic > Games and Graphics Programming > Game Demos >  [VB.Net]2d Map Creator

## dday9

*Features*
 Allows you to create maps for a game and then export them with their properties to an XML file.

*Drawbacks*
 It's pure visual basic.net, which isn't necessarily a drawback, but still vb.net is not know for it's outstanding graphics rendering. That's why most games made in vb.net use XNA or DirectX to handle the graphics. Also in my 2d Map Engine, I use a method that loads the tiles on the screen that's currently being viewed as opposed to loading the whole map and scrolling through that map which cuts down a lot of lag time.

*Plans*
 Maybe make it multi-layered. With multi-layered engines you can create the bottom layer as just ground sprites and then the upper layer(s) would store structures(buildings, tree, etc..) and movables(creatures, npc's, etc..). I also plan to implement the method mentioned in the drawback. 

*Notes*
 I plan for this to tie into loading my 2d Map Tile-Based Engine. Eventually I may convert this to XNA. Also, I don't include the sprites. You'll need to have your own sprites, and store them in a "Sprite" folder.

*Full Project - Minus .Exe*
MapGenerator.zip

*Image*

----------


## Inferrd

Hi Dave,

Nice work as usual. I found a couple of bugs, though:

The very first time you run the code, My.Settings.tile_location is set to String.Empty, so the code bugs out on the highlighted line. (tile_location will also be String.Empty). Of course, as this sub is called from the Form1 Load event handler, on a 64 bit OS the error will be swallowed while in Debug mode and the form will still show, but without any images.


```
Private tile_location As String = My.Settings.tile_location
Private tile_list As New List(Of Map_Tile)

Private Sub load_images()
    If tile_location = String.Empty Then
        MessageBox.Show("Please navigate to the folder that stores your tiles.", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning)
        Dim fbd As New FolderBrowserDialog
        fbd.RootFolder = Environment.SpecialFolder.MyComputer

        If fbd.ShowDialog = Windows.Forms.DialogResult.OK Then
            My.Settings.tile_location = fbd.SelectedPath
            My.Settings.Save()

            Dim FileDirectory As New IO.DirectoryInfo(tile_location)
            Dim FileJpg As IO.FileInfo() = FileDirectory.GetFiles("*.jpg")
            Dim FileGif As IO.FileInfo() = FileDirectory.GetFiles("*.gif")
            Dim FileBmp As IO.FileInfo() = FileDirectory.GetFiles("*.bmp")
            Dim FilePng As IO.FileInfo() = FileDirectory.GetFiles("*.png")
```

In the Board_MouseClick and board_MouseMove Subs, when you are filling blocks of multiple tiles the tiles may not go right up to the edges of the board. For example, select RadioButton3 or RadioButton5 (3x3 or 5x5) and click in the tile at location 1,1 (remembering 0,0 is the top left tile). I think this is being caused by your conditionals such as:


```
If xind - 1 > 0 AndAlso yind + 2 < board_size.Height - 1 Then
```

where they should be:


```
 If xind - 1 >= 0 AndAlso yind + 2 <= board_size.Height - 1 Then
```


When I first ran the code, the Save Button did not appear since the splitter panel had resized so as to hide it (confused me for a while  :Smilie: ). Perhaps you could set the panel it is on to be SplitContainer3's FixedPanel, and/or allow scroll bars for the panels on the left hand side of the Form.


Finally, as there are 2500 tiles on the map, it's taking a fair bit of time to add all the tiles to Panel2. I think you might be able to speed up the loading of the Form by using SuspendLayout for Panel2 while you are creating its tiles; something like:


```
'Load board
SplitContainer1.Panel2.SuspendLayout()
Call load_board()
SplitContainer1.Panel2.ResumeLayout()
```


I always enjoy your projects. Keep 'em coming!  :Smilie:

----------


## dday9

> Of course, as this sub is called from the Form1 Load event handler, on a 64 bit OS the error will be swallowed while in Debug mode and the form will still show, but without any images.


Ah that's something I didn't think about. I was always running it with a location all ready picked out, so that's something I must've overlooked!




> For example, select RadioButton3 or RadioButton5 (3x3 or 5x5) and click in the tile at location 1,1 (remembering 0,0 is the top left tile). I think this is being caused by your conditionals such as


Rookie mistake  :Stick Out Tongue: 




> When I first ran the code, the Save Button did not appear since the splitter panel had resized so as to hide it (confused me for a while ). Perhaps you could set the panel it is on to be SplitContainer3's FixedPanel, and/or allow scroll bars for the panels on the left hand side of the Form.


Could you post a screen shot of that for me, I wasn't able to reproduce it.




> I think you might be able to speed up the loading of the Form by using SuspendLayout for Panel2 while you are creating its tiles; something like:


Cool, I had no idea about Suspend/Resume Layout! That would definitely help out.

----------

