Results 1 to 5 of 5

Thread: Help with some code

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2003
    Posts
    149

    Help with some code

    Okay I got this code and it gives me an error saying object reference not set to an instance of an object. Im not sure how to fix this. The code is not good i know but im trying to make a quick tile engine and get it to work quick. Im not sure this would work. Any help about getting this thing to draw tiles and most importantly fix the error are helpful Thanx.




    VB Code:
    1. Public Structure tilesystem
    2.         Public camerax, cameray As Integer
    3.         Public startx, starty As Integer
    4.         Public tilearray As Char()()
    5.         Public offsetx, offsety As Integer
    6.     End Structure
    7.     Public Structure bimage
    8.         Public imagearray As Bitmap()
    9.         Public numframes As Integer
    10.         Public speed As Integer
    11.         Public posx, posy As Integer
    12.     End Structure
    13.  
    14. Dim graphicobject As Graphics
    15.     Dim aimage As Bitmap
    16.     Dim mimages As ArrayList = New ArrayList
    17.     Dim count As Integer = 1
    18.     Dim lrectangle As New Rectangle(0, 0, 33, 33)
    19.     Dim partimage As Bitmap
    20.     Dim bitmapimage As bimage = New bimage
    21.     Dim state As Boolean = 0
    22.     Dim avar As Integer = 1
    23.     Dim color As System.Drawing.Color = color.Black
    24.     Dim bcolor As System.Drawing.Color = bcolor.Blue
    25.     Dim atilesystem As New tilesystem
    26.    
    27.  
    28.     Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.DoubleClick
    29.         graphicobject = Me.CreateGraphics
    30.         aimage = Image.FromFile("c:\\dart\dmannoborders.bmp")
    31.         While (avar < 1000)
    32.             lrectangle.X() += 1
    33.             If (lrectangle.X() > 640) Then
    34.                 lrectangle.X() = 33
    35.             End If
    36.             partimage = aimage.Clone(New Rectangle(count * 33, 0, 33, 33), Drawing.Imaging.PixelFormat.DontCare)
    37.  
    38.             'ERROR ON THIS LINE imagearray is the problem
    39.             bitmapimage.imagearray(bitmapimage.numframes) = partimage  
    40.  
    41.             bitmapimage.numframes += 1
    42.             partimage.MakeTransparent(color)
    43.             graphicobject.Clear(bcolor)
    44.             graphicobject.DrawImage(partimage, lrectangle)
    45.             tileengine(atilesystem, 640, 480)
    46.             'Sleep(1)
    47.             count += 1
    48.             If (count > 8) Then
    49.                 count = 1
    50.             End If
    51.             avar += 1
    52.         End While
    53.     End Sub
    54.  
    55.     Public Function tileengine(ByRef atilesystem As tilesystem, ByVal resx As Integer, ByVal resy As Integer)
    56.         Dim x As Integer = resx / 32
    57.         Dim y As Integer = resy / 32
    58.         Dim count As Integer = 0
    59.         Dim count2 As Integer = 0
    60.         Dim offsetx, offsety As Integer
    61.         Dim index As Integer = 0
    62.  
    63.  
    64.  
    65.         atilesystem.startx = resx / 2
    66.         atilesystem.starty = resy / 2
    67.         atilesystem.camerax = atilesystem.startx
    68.         atilesystem.cameray = atilesystem.starty
    69.         atilesystem.offsetx = atilesystem.camerax Mod 32
    70.         atilesystem.offsety = atilesystem.cameray Mod 32
    71.         For count = 0 To y Step 1
    72.             For count2 = 0 To x Step 1
    73.                 index = Val(atilesystem.tilearray(count2)(count))
    74.                 'index into image array to get that tile
    75.                 graphicobject.DrawImage(bitmapimage.imagearray(index), lrectangle)
    76.             Next
    77.         Next
    78.     End Function
    Last edited by abcdefg; May 15th, 2004 at 03:19 PM.

  2. #2
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    is bimage a class you created?
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2003
    Posts
    149
    Yes bitmapimage is an instance of the bimage structure thats defined in the code below. I get an error trying to put a bitmap into my imagearray that holds bitmaps. Im not too familiar with VB so im probably doing something dumb.

    VB Code:
    1. Public Structure bimage
    2.         Public imagearray As Bitmap()
    3.         Public numframes As Integer
    4.         Public speed As Integer
    5.         Public posx, posy As Integer
    6.     End Structure

  4. #4
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    I'm not familiar with graphics, but I'd bet the problem is the line of code above the one throwing an exception. partimage is likely being set to Nothing. That works, not like you want it to, but throws the exception when you try to use it.
    Try checking the error line with If Not partimage = Nothing Then...
    At least that's my experience with that type of error.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2003
    Posts
    149
    Nevermind I got it. I just needed a constructor for my struct that made a new instance of the array

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width