Visual basic tile map

Posted on 2003-03-14
Medium Priority
Last Modified: 2009-07-29
I am just wondering what is the best way of doing this for smoothest operation.  I will be making a tile map that they can right click on the map and move map up and down in the form.  The form will take up about a 4th of the screen and by clicking on castles on the map other forms pop up to give them choices to do things.  I was wondering what would be the smoothest for the map scrolling around, they will be pretty large maps so I cant draw whole map at once.  Things I have seen are api calls and direct x just wondering if anyone out there knows much about this?  If so i will be asking more questions in direct relation to your answer and will keep feeding you points for each question.
Thanks in advance.
Question by:Hook333
  • 3
  • 2

Expert Comment

ID: 8138138
You should definitely use a double-buffer technique.  I have used two offscreen PictureBoxes and used the GDI BitBlt function to paint only the required section of the screen from the pb used as the source map to the pb used as the back buffer.  Then I use BltFast to move the image from the back buffer pb to the visible picture box.  I could probably post some example code if necessary.

Author Comment

ID: 8139746
the example code would be awesome I will up the points to 350 for the sample code.  Also is there a way to direct you to my future questions as I will have more but want to give all points to one person who is helping me with them?
Thanks for the help.

Accepted Solution

Hermetic earned 1400 total points
ID: 8140210
Three PictureBoxes.
In the original source, there were a couple of scroll bars
and alot of code to get them positioned just right.  I have omitted it to make the example more clear.
The Picture Boxes are all set to scalemode vbPixel.
The Backbuffer and Source are set to AutoRedraw.
Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByBal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC as Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

Public Sub RefreshMap()
   'picSrc = Invisible Picture Box containing whole map
   'picBack = Invisible Picture Box for back buffer and work.
   'picDest = Picture Box for displaying to user.

   Dim picSrc As PictureBox
   Dim picBack As PictureBox
   Dim picDest As PictureBox

   Dim StartX As Long
   Dim StartY As Long

   Set picSrc = MainForm.pbSource
   Set picBack = MainForm.pbBack
   Set picDest = MainForm.pbMap

   StartX = -MainForm.HScrollMap.Value
   StartY = -MainForm.VScrollMap.Value

   BitBlt picBack.hDC, 0, 0, _
        picBack.ScaleWidth, picDest.ScaleHeight, _
        picSrc.hDC, StartX, StartY, vbSrcCopy

   'Do other things to picBack here like draw
   'on map text messages, sprites, etc.

   BitBlt picDest.hDC, 0, 0, _
        picDest.ScaleHeight, picDest.ScaleWidth, _
        picDest.hDC, 0, 0, vbSrcCopy

End Sub

As for directing questions directly to me, that is not the
typical format of this forum.  I think people typically
use the subject line to say "Question for:" but I wouldn't
recommend it.  There are quite a few experts in here and
it pays to hedge your bets.

Author Comment

ID: 8140559
ok I will keep them open then I was just going to let you know when I posted new ones so you could look at them.  thanks for the help I will award you the points for this one.

Author Comment

ID: 8140565
did you get the 350 points?

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month8 days, 14 hours left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question