Tile Editor RRS feed

  • Question

  • I'm trying to make a tile editor, but I cant figure out how to draw the tiles. I have drawn a grid, but I'm trying to make a Tile class and I don't know where I would put the draw function, whether it would be in the tile class itself or whether it would be somewhere else. my code so far is:


    Imports System.Drawing.Drawing2D
    Public Class Tile
      Dim UpperLeftX As Integer
      Dim UpperLeftY As Integer
      Dim Width As Integer
      Dim Height As Integer
      Dim Layer As Integer
      Dim Visible As Boolean
      Dim x1 As Integer
      Dim y1 As Integer
      Dim x2 As Integer
      Dim y2 As Integer
      Sub Draw(ByVal x1, ByVal y1, ByVal x2, ByVal y2)
      End Sub
    End Class
    Public Class Form1
      Dim grid As Tile
      Public Sub DrawGrid(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        Dim x As Integer
        Dim y As Integer
        For x = 0 To Me.Width - 32 Step 32
          e.Graphics.DrawRectangle(Pens.Black, x, y, 32, 32)
          For y = 0 To Me.Height - 32 Step 32
            e.Graphics.DrawRectangle(Pens.Black, x, y, 32, 32)
          Next y
        Next x
      End Sub
    End Class

    Tuesday, May 11, 2010 12:25 AM


  • It would probably be easier if your tile class inherits from another class like a label or button for example . Controls like the label inherit from other classes like the control class which has methods and functions already that you do not need to rewrite . For example the click function of a label is inherited from the control class and as such you can handle the click event of a label with an event handler. You can override the functions or handle the events such as the paint event . In other words you start with a base class and modify it in your derived class .

    Here is a link to a multidimensional Tic Tac Toe game project that might be worth looking at . Multi Tic Tac Toe

    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read . Or use the Forum Code Formatter by JohnWein http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/bf977a14-d9d4-4e84-9784-bf76b9e23261

    Tuesday, May 11, 2010 4:36 AM