I have just gotten a grasp of how it works.. I think.
I'll just show Where I'm at right now.

Public Class Face
'global variables
Dim x, y As Integer
Dim map(x, y) As Integer 'Not sure if this should be a Integer but if I run into errors later I'll just try something else than integer

Private Sub Face_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    For y = 0 To 10 'I'm just testing with 10 to see if it works at all.... which it isn't
        For x = 0 To 10
            e.Graphics.DrawImage(New Bitmap("grass.jpg"), (Me.ClientSize.Width - Me.ClientSize.Width) + (35 * x), (Me.ClientSize.Height - Me.ClientSize.Height) + (35 * y)
            x += 1
        y += 1
End Sub
End Class

The Attachment to this post is a picture of the debug so you can see how wrong this became.
The picture is 35width and 35height btw, So first thing I don't understand is why are there gaps between every tile?
Second thing I wonder is why is there only 6 tiles in width and 6 tiles in height? should be 10 or 11.
If you could answer those 2 questions I have I'll be happy :)
Also I would be even happier if you could tell me if I'm on the right way to making a tile map or if I'm doing it completely wrong etc.

Looking forward for any help I can get :)

Attachments grass_tiles_wrong.JPG 18.92 KB
9 Years
Discussion Span
Last Post by mansoordexter

Couple of questions from me...

(Me.ClientSize.Width - Me.ClientSize.Width)


(Me.ClientSize.Height - Me.ClientSize.Height)

both of these subexpressions will surely always evaluate to 0 right? They seem totally unecessary.. You have a missing closing bracket somewhere.. also, you're incrementing the loop variables x and y manually. don't do this. so, take out the statements x += 1 and y += 1. That should fix the problem with less than 11 tiles across the x and y.. as for the gaps between the tiles... are you sure that the units in the method you're using and the units you're measuring the image in are the same? I would have expected that pixels would be used as units in the draw method, but, the MSDN site for this method gets confusing, talking about 'physical width' and 'pixel width', and doesn't specifically mention the units expected for x/y...


So.. Just to try it out, and see if it is a problem with units, try this please:

Private Sub Face_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    For y = 0 To 10
        For x = 0 To 10
            'Using another flavour of this function, this time providing width and height explicitly, and assuming that the units will be the same for placement as they are for size
            e.Graphics.DrawImage(New Bitmap("grass.jpg"), ( 35 * x ), ( 35 * y ), 35, 35 )
End Sub

Report back any changes..


Thanks for your help!
Those incrementals I had was what was messing that code up.
As soon as I removed them there were no gaps and all 11X11 tiles showed up.
Also, yes. the "(Me.ClientSize.Width - Me.ClientSize.Width)" and other one but with Height was really useless hehe.
My thought behind adding that was because I Dont want my tiles to come underneath the forms Borders.
It seems like the tiles are inside the borders anyway automatically.

So yeah.. Thanks for your help again :)


I've gotten further now with the learning of making a Tile Map.. Thanks to a very good tutorial.
Ran into a problem though.

Here's the code.

Imports System.IO
Public Class clsMap
    Dim SR As StreamReader

    Public NumColumns As Integer
    Public NumRows As Integer
    Public Tiles(,) As Bitmap

    Dim NumOfTiles As Integer

    Public Sub ReadMap(ByVal MapFile As String)
        SR = New StreamReader(MapFile)
        Dim ln As String
        ln = SR.ReadLine()
        Dim str() As String
        str = ln.Split(CChar(","))
        NumColumns = CInt(CDbl(str(0)) - 1)
        NumRows = CInt(CDbl(str(1)) - 1)
        ReDim Tiles(NumColumns, NumRows)
        Dim CurrentRow As Integer
        Dim CurrentColumn As Integer
        Dim Line() As String

        For CurrentRow = 0 To NumRows
            ln = SR.ReadLine()
            Line = ln.Split(CChar(","))
            For CurrentColumn = 0 To NumColumns
                Tiles(CurrentColumn, CurrentRow) = new Bitmap("tiles\" & Line(CurrentColumn) & ".jpg")
    End Sub
End Class


Public Class Face
    Dim map As clsMap
    Dim PushedOtherKey As Boolean

Private Sub Face_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    map = New clsMap()
End Sub

Private Sub Face_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    Dim x ,y As Integer
    For x = 0 To map.NumColumns
        For y = 0 To map.NumRows
            e.Graphics.DrawImage(map.Tiles(x, y), x * 35, y * 35)
End Sub
End Class

The error I get when trying to Debug this is "Object reference not set to an instance of an object." Which I have no idea what it means.
It is Pointing at the Line: 30

Tiles(CurrentColumn, CurrentRow) = new Bitmap("tiles\" & Line(CurrentColumn) & ".jpg")

I'm so close to finally being able to make tile maps it feels like it's just this error in my way.
Please help me.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.